views:

1107

answers:

1

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

A: 

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.

Joshua Drake
Another -- albeit more hacky -- option is to find the proper windows messages and in the WndProc override of a derived control,*(e.g. MyGrid : DataGridView),* intercept those and based on the mouse position, selected row count...etc, either let the default processing happen or provide custom handling... The up side is no flash as the selected rows don't get wiped out then restored. . . The down side is much more complicated code to maintain.
Jason D