Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi all!
i have a problem is.. i dont know handles event when i clicking on button in datagridview, i design my form like below picture
 
http://nj4.upanh.com/b5.s25.d1/1b608c451153dc01b7dd697ba98e7643_41785524.nhchupmanhinh20120308145028.png[^]
 
i want when i clicked on the button then it show the infor of that row. Please reply me soon or mail me with Email: [removed]
Posted 7-Mar-12 20:55pm
Edited 7-Mar-12 20:56pm
v2
Comments
walterhevedeich at 8-Mar-12 2:57am
   
I've removed your email address. If someone knows the answer, they will be posting it here, not on your email.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please, look at your screen.
 
Why the heck do you want a button on each and every row which does exactly the same thing, but for a different row of data?
All the buttons are doing is wasting screen real-estate and making it look clumsy.
 
Why not just show the data for the currently selected row? That way the user doesn't have to click on a button at all - when the selected row changes, the information is automatically updated.
Or, if you are bringing up a dialog to show the data, consider a single button which shows the data for the selected row? Again, it reduces the screen footprint, and looks less "busy". It's also pretty simple for the user to work out - the button is always in the same place, rather than moving with the row.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you are using the TemplateField object and have to access the row index in the event handler method, set the button's CommandArgument property to an expression that identifies the current row. Sample code is:
 
<asp:TemplateField>
  <ItemTemplate>
    <asp:Button ID="AddButton" runat="server"
      CommandName="AddToData"
      CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
      Text="Add to Cart" />
  </ItemTemplate>
</asp:TemplateField>
 
Create a method for the RowCommand event of the GridView control as:
protected void GridView1_RowCommand(object sender,
  GridViewCommandEventArgs e)
{
  if (e.CommandName == "AddToData")
  {
    // Add code here to related to the row.
  }
 
  }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Ok i using vb.net not c# Big Grin | :-D i testing hanldes event on datagridview Big Grin | :-D
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

i have just complete Big Grin | :-D it run ok. this is my code.
 
Private Sub gvView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gvView.CellContentClick
        Dim strID As String
        Dim strName As String
        Dim strPricw As String
        Dim strQuan As String
        If e.ColumnIndex = 0 Then
            strID = gvView.Rows(e.RowIndex).Cells(3).Value.ToString()
            strName = gvView.Rows(e.RowIndex).Cells(4).Value.ToString()
            strPricw = gvView.Rows(e.RowIndex).Cells(5).Value.ToString()
            strQuan = gvView.Rows(e.RowIndex).Cells(6).Value.ToString()
            MessageBox.Show("You has choosen: " & strID & " | " & strName & " | " & strPricw & " | " & strQuan)
        End If
    End Sub
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 626
1 OriginalGriff 311
2 Maciej Los 210
3 Mehdi Gholam 145
4 PIEBALDconsult 140
0 Sergey Alexandrovich Kryukov 11,384
1 OriginalGriff 5,783
2 Maciej Los 5,684
3 CPallini 3,879
4 BillWoodruff 3,584


Advertise | Privacy | Mobile
Web02 | 2.8.141030.1 | Last Updated 8 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100