TSFLLC
asked on
Datagridview issue with CurrentRow.Index not having been established
I have this piece of code included on a tabpage that I originally had set with .SelectionChanged, but it would error when the rowheader was clicked. My issue is that the CurrentRow.Index is not set when I click outside an actual row. The code below, I realize now with RowEnter, has not initialized CurrentRow.Index.
What can I modify about this code where if a row becomes active in any certain way (clicked, coded, etc.) and also if headers are clicked that I can handle CurrentRow.Index. Do I just need to create an error handler with some 'ignore' code. I'm skeptical about that because of my 'PopulateParticipants' Sub where data is drawn from a dataview.
Thanks in advance!
What can I modify about this code where if a row becomes active in any certain way (clicked, coded, etc.) and also if headers are clicked that I can handle CurrentRow.Index. Do I just need to create an error handler with some 'ignore' code. I'm skeptical about that because of my 'PopulateParticipants' Sub where data is drawn from a dataview.
Thanks in advance!
Private Sub grdviewParticipants_RowChg(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdviewParticipants.RowEnter
If Activating Then Exit Sub
Activating = True
If dvParticipants.Count > 0 Then
If grdviewParticipants.CurrentRow.Index >= 0 Then
grdviewParticipants.CurrentCell = grdviewParticipants.Item(3, grdviewParticipants.CurrentRow.Index)
glCurrentParticipantRow = grdviewParticipants.CurrentRow.Index
glParticipant = dvParticipants(grdviewParticipants.CurrentRow.Index)("participant_id").ToString
PopulateParticipants()
End If
End If
Activating = False
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got complacent. This actually reduces the need for a grdview.MouseClick that I have on multiple gridviews in order to populate fields. Instead of using CurrentRow.Index AT ALL.....use of e.RowIndex takes care of all the problems I had or may have in the future I think with populating fields from accessing the grid.
Thanks much again!