Data Grid: How do you unselect a row? Error: Index was out of ran

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using the vb .net datagrid for windows forms. How do you unselect the
current row on the dataset? I tried the following:

If (mygrid.CurrentRowIndex <> -1) Then
mygrid.UnSelect(mygrid.CurrentRowIndex())
End If

This does not always set the mygrid.CurrentRowIndex to -1 (As I have found
while debugging)! This is a problem because after this line I set the
datasource and the datamember properties and when mygrid.CurrentRowIndex is
not -1, an error occurs: "Index was out of range. Must be non-negative and
less than the size of the collection."

Any help is appreciated.
 
You cannot set the currentRowIndex to -1. Setting it to a negative number
causes an error.

I have found a solution to the problem. I was using multiple table styles
at the same time; I assumed that the datagrid would pick the table style that
matches the datamember property. However, I not sure that is was because I
now figure out which style I need and add it in code, and I no longer get
that error.

Thank you for your help.
 
Back
Top