>Here is the code that does the trick for me.
Your code has overloads and properties that are not available to me, but
after adjusting it to compile, IT WORKS! I tried code very similar to yours
in my experiments, but I don't think I actually extracted the cell value,
flipped it and set it again like you do. Jeez I must have been close. Thanks
for pointing me in the right direction after such a long period of
hopelessness on this. My code is below and you will that I check for the
correct row and column along with some other subtle differences.
Thanks heaps,
Greg
/// <summary>
/// This handler is a workaround for a problem where the CheckBox column
cell in the
/// top row (top row only!) will not respond to mouse clicks and change
state.
/// </summary>
private void gridRU_MouseUp(object sender, MouseEventArgs e)
{
DataGridView.HitTestInfo hti = gridRU.HitTest(e.X, e.Y);
if ((hti.Type == DataGridViewHitTestType.Cell) && (hti.RowIndex == 0))
{
DataGridViewColumn col = gridRU.Columns[hti.ColumnIndex];
if (col.Name == colSelected.Name)
{
DataGridViewCell cell =
gridRU.Rows[hti.RowIndex].Cells[hti.ColumnIndex];
bool selected = (bool)cell.Value;
cell.Value = !selected;
gridRU.EndEdit();
gridRU.InvalidateRow(hti.RowIndex);
}
}
}
private void MyDataGrid_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
DataGrid senderGrid = sender as DataGrid;
DataGrid.HitTestInfo hti = senderGrid.HitTest(e.X, e.Y);
if (hti.Type == DataGrid.HitTestType.Cell && "check here that the right
cell has been clicked")
{
bool itemChecked = !(bool) senderGrid[hti.Row, hti.Column];
senderGrid[hti.Row, hti.Column] = itemChecked;
senderGrid.EndEdit(MyDataGrid.TableStyles[0].GridColumnStyles[hti.Column],
hti.Row, false);
senderGrid.Refresh();
}
}