我有问题。当我使用datagridview加载表单时,我希望在单击>时将数据传输到文本字段。在datagridview的最左边。 现在,我必须选择行本身的内容来选择一行。如何设置它以便根据最左侧的行选择器选择行?而不是让我点击行的内容? dtguser_CellContentClick让我根据内容点击选择权限?如果我想要整行选择应该是什么?
Private Sub dtguser_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtguser.CellContentClick
If GroupBox3.Enabled = False Then
Else
'this code will simply pass the value from the specific row selected by the user
lblid.Text = dtguser.CurrentRow.Cells(0).Value
serial.Text = dtguser.CurrentRow.Cells(0).Value
fname.Text = dtguser.CurrentRow.Cells(1).Value
lname.Text = dtguser.CurrentRow.Cells(2).Value
gender.Text = dtguser.CurrentRow.Cells(3).Value
address.Text = dtguser.CurrentRow.Cells(4).Value
contact.Text = dtguser.CurrentRow.Cells(5).Value
course.Text = dtguser.CurrentRow.Cells(6).Value
datestart.Text = dtguser.CurrentRow.Cells(7).Value
datecomplete.Text = dtguser.CurrentRow.Cells(8).Value
datecertify.Text = dtguser.CurrentRow.Cells(9).Value
nationality.Text = dtguser.CurrentRow.Cells(10).Value
email.Text = dtguser.CurrentRow.Cells(11).Value
certification.Text = dtguser.CurrentRow.Cells(12).Value
End If
End Sub
答案 0 :(得分:3)
如果要选择整行,请将选择模式设置为FullRowSelect
。
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
如果您想在点击RowHeader(>按钮)时获取数据,请订阅RowHeaderMouseClick
事件。
dataGridView1.RowHeaderMouseClick += new DataGridViewCellMouseEventHandler(dataGridView1_RowHeaderMouseClick);
Private Sub dataGridView1_RowHeaderMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs)
// put your code for copying row data into the textboxes.
End Sub