在Winform中,DataGridView中使用Checkbox控件时
//单击单元格事件
private void dgvTables_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
DataGridViewCheckBoxCell dgvCheck = (DataGridViewCheckBoxCell)dgvTables.Rows[e.RowIndex].Cells[0];
if (dgvCheck.Selected)
{
dgvCheck.Value = !((bool)dgvCheck.FormattedValue);
}
}
}
本文介绍在 Winform 应用程序中如何使用 DataGridView 控件内的 Checkbox 实现单元格点击时的状态切换。通过简单实用的代码片段,展示了如何监听单元格点击事件,并在 Checkbox 被点击时反转其状态。
1555

被折叠的 条评论
为什么被折叠?



