DataGridView Data Item Click Event in VS 2010

I'm a little new for DataGrid controls, but I'm just wondering why the first block of code below works, but the second block of code does not work? (The only thing I see is Handles the DataGridClaims  Syntax

Block 1

Private Sub DataGridClaims_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridClaims.CellContentClick
    If e.RowIndex <> -1 Then
        Dim frmViewClaims As New objViewClaim
        frmViewClaims.ClaimID = DataGridViewClaims.CurrentRow.Cells("ClaimNum").Value
        frmViewClaims.Show()
    End If
End Sub

Block 2

Private Sub DataGridClaims_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
    If e.RowIndex <> -1 Then
        Dim frmViewClaims As New objViewClaim
        frmViewClaims.ClaimID = DataGridViewClaims.CurrentRow.Cells("ClaimNum").Value
        frmViewClaims.Show()
    End If
End Sub
+3
source share
2 answers

The "handles" keyword in VB.net marks a function as a listener for a given event. Without "Handles DataGridClaims" the grid will not be able to learn how to run your function when an event is triggered.

[Cm. MSDN Doc's] [1] http://msdn.microsoft.com/en-us/library/6k46st1y(v=VS.100).aspx

+2
source

VB.NET, CellContentClick - , .

, , Handles VB.NET. .

+= #

DataGridClaims.CellContentClick += DataGridClaims_CellContentClick;

+2

Source: https://habr.com/ru/post/1784150/


All Articles