Public Sub LoadDataAS() grdApplicantsAS.DataSource = Nothing grdApplicantsAS.Columns.Clear() txtSearchBar1.Clear() mycom.Connection = cn mycom.CommandText = "SELECT concat_ws(',', LastName, FirstName, MiddleName) as 'Applicant Name',EDate as 'Date of Examination', EScore as 'Examination Score', IStatus as 'Interview Status',IComment as 'Interview Comment' FROM tbl_applicant" Dim myadap As New MySqlDataAdapter(mycom) Dim mydt As New DataTable myadap.Fill(mydt) grdApplicantsAS.DataSource = mydt Dim buttonColumn As New DataGridViewButtonColumn() buttonColumn.HeaderText = "" buttonColumn.Name = "Status Request" buttonColumn.Text = "Hire" buttonColumn.UseColumnTextForButtonValue = True grdApplicantsAS.Columns.Add(buttonColumn) Dim buttonColumn1 As New DataGridViewButtonColumn() buttonColumn1.HeaderText = "" buttonColumn1.Name = "Status Request" buttonColumn1.Text = "Regrets" buttonColumn1.UseColumnTextForButtonValue = True grdApplicantsAS.Columns.Add(buttonColumn1) myadap.Dispose() mydt.Dispose() End Sub
我的数据表的每一行分别具有两个按钮租用和遗憾,我的数据表的一列包含电话号码,我无法弄清楚,如何获得单击按钮租用并将其传递给另一行的同一行的编号表格..非常感谢您的帮助
为此,您可以使用您的CellClick事件DataGridView,请参阅下文。
CellClick
DataGridView
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
表格2范例
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