C#DataGridView复选框独立于行选择 [英] C# DataGridView checkbox independant from row selection

查看:146
本文介绍了C#DataGridView复选框独立于行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

thx提前为帮助...
我有一个datagridview(c#Winforms)与一列复选框。单击其中任何一个时,它会自动选择该行。 (虽然不是其他方式)。如何解除行选择从复选框的checcking?换句话说,我想启用多个行选择,而不会影响相应的复选框,并且还单击多个复选框,而不自动选择复选框选中的行?
〜Ron

thx in advance for the help... I have a datagridview (c# Winforms) with a column of checkboxes. When any of these are clicked, it automatically selects the row. (Although not th eother way around). How do I de-couple row selection from the checcking of the checkbox ? In other words, I want to enable multiple row selection, without effecting the corresponding checkboxes, and also click multiple checkboxes without "automatically selecting" the rows where the checkboxes are "checked" ? ~Ron

推荐答案

我不知道这是不是你要找的,但希望它会指向你在正确的方向。如果要确保在编辑单元格的值时没有选择行,您可以处理DataGridView的CellBeginEdit事件。

I am not certain if this is what you are looking for, but hopefully it will point you in the right direction. If you want to make certain that no rows are selected when you edit the value of a cell you can handle the CellBeginEdit event of the DataGridView.

this.dataGridView1.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(dataGridView1_CellBeginEdit);

void dataGridView1_CellBeginEdit(object sender, System.Windows.Forms.DataGridViewCellCancelEventArgs e)
{
 dataGridView1.ClearSelection();
}

如果要维护现有选择,则需要实施更复杂处理程序,例如保存当前选定行的索引并在之后恢复。

If you want to maintain the existing selection you will need to implement a more complex handler, such as saving the indexes of the currently selected rows and restoring them after.

这篇关于C#DataGridView复选框独立于行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆