DataGridView CellContentClick event handler not being invoked

Hello,

There is something strange going on in my VB 2005 program that I don't understand...

I have a form that has several tab pages. Each page has one or more DataGridView controls.

When a user selects an item on one DataGridView , I want to deselect anything currently selected on any other DataGridView on that tab page. The only thing that should then be selected is the item I clicked on in the current DataGridView .

I created the following code (note there is a CellContentClick handler for each DataGridView control and there are DeselectAll... and RefreshAll... subroutines for each tab page).

It's fairly straightforward. But notice where I placed the XXX NOTE comment below. If I place a breakpoint there, run the program and click on various cells in various grids, and then click on the specified grid cell, I can create situations where the breakpoint is never reached! Thus, I don't turn off the selection in other grids.

How can this be? Is there some setting for DataGridView controls that I've inadvertently set incorrectly (without my listing them all here)? Or is there some bug in VB I'm unaware of? The "DeselectAll" subroutine merely iterates over all DataGridView controls in the current tab page (except for the current DataGridView) and calls ClearSelection on each such grid. RefreshAll calls Refresh on every DataGridView on the current tab page.

Thanks!

'========================================

PrivateSub gridEmergencyDiagnosticEvents_CellContentClick(ByVal senderAs System.Object,ByVal eAs System.Windows.Forms.DataGridViewCellEventArgs)Handles gridEmergencyDiagnosticEvents.CellContentClick

DeselectAllEmergencyGrids(gridEmergencyDiagnosticEvents) ' XXX NOTE - I put a breakpoint here! XXX

RefreshAllEmergencyGrids()

EndSub

[2617 byte] By [S.Paris] at [2007-12-24]
# 1

I too have this problem, DataGridView randomly ignores mouse clicks so sometimes the _CellContentClick event does not run.

is this a bug? Service pack Issue? Is there any fix in sight? This seems to be a problem that's been hanging around for a long time, I see it in other forums, such as the following.

http://www.xtremevbtalk.com/showthread.php?t=283163&referrerid=157353

Bottom Line: How can I make DataGridView not ignore _CellContentClick events?

Mike the Spock Monster

SpockMonster at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Have you tried the CellEnter event? If all that is required is for the user to select a cell then it maybe it's not necessary to trap for the CellContentClick event. You just may need to test for e.rowIndex = -1 or e.ColumnIndex = -1 (the row and column headers being clicked) with this approach.

I believe this will also be hit when the user presses the arrow keys to navigate through the datagridview (since it fires off when the CurrentCell property changes). The only problem may be that it also gets raised when the input focus is set for the datagridview when it previously did not have it. In that case you may have to test for that condition so it doesn't fire twice with a single click.

DigBoy2000 at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

Thanks DigBoy, I'll play around with that.

But attention Microsoft, I'd still like to have a working _CellContentClick event, can you advise?

SpockMonster at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

As it turns out, the user must actually click on the content of the cell, not just the cell, in order to invoke the DataGridView CellContentClick method. Pretty annoying. I have not personally tried other handlers as CellContentClick is the one provided for coding when double-clicking the control in the form designer. Still getting my feet wet with C#...

JeffGordon at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
I ended up changing this to CellClick in both the Form1.cs and Form1.Designer.cs and it works no matter where the user clicks in the cell.

JeffGordon at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...