How to get row values of a datagridview and pass it to another form using a button in thesame row

前端 未结 1 866
谎友^
谎友^ 2021-01-25 19:18
Public Sub LoadDataAS()
    grdApplicantsAS.DataSource = Nothing
    grdApplicantsAS.Columns.Clear()
    txtSearchBar1.Clear()
    mycom.Connection = cn
    mycom.Comman         


        
相关标签:
1条回答
  • 2021-01-25 19:39

    To do this you can use the CellClick event of your DataGridView, please see below.

      Private Sub grdApplicantsAS_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles grdApplicantsAS.CellClick
            Dim frm2 As Form2
            Try
                'First column button
                If e.ColumnIndex = 0 Then
                   frm2 = New Form2(grdApplicantsAS.CurrentRow.Cells(YOUR NUMBER COLUMN).Value.ToString())
                   frm2.ShowDialog()
                ElseIf e.ColumnIndex = 1
                   'Do what you need here for the other button...
                End If             
    
            Catch ex As Exception
            End Try
        End If
    End Sub
    

    FORM 2 EXAMPLE

     Public Class Form2
       Public Property EmployeeName As String
    
       'Pass your name in as the argument. Now Form 2 will have your name...
       Public Sub New(ByVal strEmployeeName As String)
    
         'Set your property of your employee name
         EmployeeName = strEmployeeName
    
       End Sub
    
     End Class
    
    0 讨论(0)
提交回复
热议问题