NewBe Gettin a valid object reference

I have a DataGridView populated from a DataTable. I have added a routing to catch when the selected row changes as shown below. My problem is that the softwarecomplains of a Null reference to the DataGridView. How can I get a proper reference to the sending Object? Is the Object not directly the control?

Thanks

JD
--

PrivateSub graphicGrid_RowStateChanged(ByVal senderAsObject,ByVal eAs System.Windows.Forms.DataGridViewRowStateChangedEventArgs)Handles graphicGrid.RowStateChanged

' A new Cell has been selected

Dim glyphGridAs DataGridView =DirectCast(sender, DataGridView)

Dim NameStr, DescriptionStrAsString

Dim SqlAsString

Dim b(256)AsByte

Dim dataRowAsInteger

'Obtain the graphics blob from the database

dataRow = glyphGrid.CurrentRow.Index

NameStr = glyphGrid(0, dataRow).Value

DescriptionStr = glyphGrid(1, dataRow).Value

[2535 byte] By [JDeas] at [2008-2-1]
# 1

If you are following the normal guidelines, the Sender *should* be the control. This is the case whenever the control generates the event. Please note that there is nothing that prevents you from directly calling the graphicGrid_RowStateChanged method and passing in just about anything as the sender parameter (not that I'd recommend that you'd do so)

I suspect that it is the glyphGrid.CurrentRow that is Nothing (or Null) when you try to get the Index from it, and not the glyphGrid itself. This would explain the Null Reference Exception.

Please note that the DataGridViewRowStateChangedEventArgs has a "Row" property, from which you can get the row that the state changed for...

Best Regards,
Johan Stenberg

JohanStenberg at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic Language...