DataGridView输出的表格中,如何做到点击左边,就能选中行,并对行中数据进行操作?
例如:
点击红点部分就能选中整行。然后将行中数据放入其他Text.Box中。
Dim index As Integer
index = DataGridView1.CurrentCell.RowIndex
If DataGridView1.Rows(index).HeaderCell.State = DataGridViewElementStates.Selected Then
banji.Text = DataGridView1.CurrentRow.Cells("班级").Value.ToString
xingming.Text = DataGridView1.CurrentRow.Cells("姓名").Value.ToString
shouji.Text = DataGridView1.CurrentRow.Cells("手机").Value.ToString
End If
?DataGridView 选中行
[解决办法]
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
dataGridView1.Rows[e.RowIndex].Selected = true;
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
}
Private Sub DataGridView1_RowHeaderMouseClick(byval sender as object , byval e as DataGridViewCellMouseEventArgs ) Handles dg1.RowHeaderMouseClick
if(e.RowIndex>=0) then
banji.Text= dg1("班级",e.RowIndex).Valut.ToString()
xingming.Text= dg1("姓名",e.RowIndex).Valut.ToString()
shouji.Text= dg1("手机",e.RowIndex).Valut.ToString()
end if
end sub