Datagridview 强制在一列中只选择一个复选框 [英] Datagridview forcing only one checkbox to be selected in a column
本文介绍了Datagridview 强制在一列中只选择一个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何强制在 Datagridview 的列中只选中一个复选框?
How do I force only a single checkbox to be checked in a column of a Datagridview?
推荐答案
你必须订阅网格的 CellValueChanged
事件,并根据当前单元格的检查状态,循环 DataGridView并将其他单元格的值设置为 true/false.
You will have to subscribe for the CellValueChanged
event of the grid and depending on the check state of the current cell, loop the DataGridView and set true/false as Value for the other cells.
void grd_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if ((sender as DataGridView).CurrentCell is DataGridViewCheckBoxCell)
{
if (Convert.ToBoolean(((sender as DataGridView).CurrentCell as DataGridViewCheckBoxCell).Value))
{
// Maybe have a method which does the
//loop and set value except for the current cell
}
}
}
这篇关于Datagridview 强制在一列中只选择一个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文