I have a few thoughts. First, have you set the DataGridView's
MultiSelect, SelectionMode, or EditMode attributes or left them on
their default settings? If you could show us your code for when you
create your DataGridView and when you set it's attributes that would
help.
Thanks for the feedback. I've have in fact set all of the above using the VS
forms designer so it all takes place in "InitializeComponent()"
MultiSelect = false
SelectionMode = CellSelect
EditMode = EditOnKeystrokeOrF2
I agree that using the CellEnter event is a bad idea since that could
cause an infinite loop.
I've taken precautions against this. The error I cited previously however
appears to be a bug not only because I've read about others who have the
same problem, but because the manager of the "DataGridView" class at MSFT
(Mark Rideout) acknowledged it's a bug under other circumstances (on the
MSFT forums site).
I cannot replicate your problem with left
clicked when using the CellMouseDown event. I have tried using both
the CellMouseDown and the CellMouseClick events and they both register
for left-click and right-click. I'm hoping that once I know how you
have your attributes set I will be able to replicate your problem. If
possible please also supply your code for the CellMouseDown event.
Well, I just tried this by creating a new app out-of-the-box. I added a
"DataGridView" as the only control on the form with two textbox columns. I
then created a "CellMouseDown" handler as follows:
private void m_Grid_CellMouseDown(object sender,
DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex == 0)
{
m_Grid.CurrentCell = m_Grid[1, 0];
}
}
When the app starts, column 0 is automatically the current column. If I now
right-click column 0 then the handler is called (just once) and column 1
becomes current as expected. If I left-click column 0 however then the
handler is also called (just once) but column 0 remains current. I can
understand why this is probably occurring (left-clicking makes the cell
current *after* the handler exits) but it's incorrect behaviour IMO (since
the handler's code should override the left-mouse click). Any ideas? Thanks.