WinForm DataGridView选中行设置
文章目录
- WinForm DataGridView选中行设置
- 添加checkbox列
- 列和选中行效果
- 选中行代码
添加checkbox列
列和选中行效果
选中行代码
public Basic_configuration()
{
InitializeComponent();
...........
//添加鼠标事件
this.dataGridView_basic.CellMouseUp += DataGridView1_CellMouseUp;
.......
}
private void DataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (e.ColumnIndex > 0)
{
for (int i = 0; i < dataGridView_basic.Rows.Count; i++)
{
dataGridView_basic.Rows[i].Cells[0].Value = false;
}
for (int i = 0; i < dataGridView_basic.SelectedRows.Count; i++)
{
dataGridView_basic.Rows[dataGridView_basic.SelectedRows[i].Index].Cells[0].Value = true;
}
}
}
}
DataGridVIew序号设置可看这篇