Link to home
Start Free TrialLog in
Avatar of mgmhicks
mgmhicks

asked on

Sorting datagridview in winforms

I have a datagridview bound to a dataset and I have a couple of columns that I allow for automatic sorting.  The issue is that i have this code in the datagrids_selectionChanged event.
 If dgCollections.CurrentRow.Index = Nothing Then
        Else
            Dim i As Integer = dgCollections.CurrentRow.Index
            If Trim(dgCollections.Item(8, i).Value) <> "Pay Plan" Then
                btnPayPlan.Visible = False
            Else
                btnPayPlan.Visible = True
            End If
        End If

Now when I click the header to sor the column, it runs this code and errors on dgcollections.currentrow.index because it has a value of nothing.  I do need this code when someone selects a different row.

thanks
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mgmhicks
mgmhicks

ASKER

thank you