Fordraiders
asked on
Datagrid View selection changed event problem
vb.net 2003
sql express 2005
What I have :
My users have a textbox to type in a search string
They press the <Enter> button and the datagrid shows the results.
I have 3 additional textboxes that show the current datagrid row as they scroll in the datagrid itself.
If the user want to do another search. They go back into the searcbox and type in a new criteria.
Problem: In order to avid a null error on this line.
Me.DataGridView1.CurrentRo w.Cells(0) .Value <-------------
I cheated and use the on "error resume next" opt out.
Question: Is there a better way to capture the Null Value error that generates because of the "SelectionChangted" event ?
Thanks
fordraiders
sql express 2005
What I have :
My users have a textbox to type in a search string
They press the <Enter> button and the datagrid shows the results.
I have 3 additional textboxes that show the current datagrid row as they scroll in the datagrid itself.
If the user want to do another search. They go back into the searcbox and type in a new criteria.
Problem: In order to avid a null error on this line.
Me.DataGridView1.CurrentRo
I cheated and use the on "error resume next" opt out.
Question: Is there a better way to capture the Null Value error that generates because of the "SelectionChangted" event ?
Thanks
fordraiders
Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
On Error Resume Next
Me.TextBox3.Text = Me.DataGridView1.CurrentRow.Cells(0).Value
Me.TextBox4.Text = Me.DataGridView1.CurrentRow.Cells(1).Value
Me.TextBox5.Text = Me.DataGridView1.CurrentRow.Cells(2).Value
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To expand on strickdd's comment, you may need to check each level to see if that object is null:
If Not Me.DataGridView1.CurrentRo w Is Nothing andalso Not Me.DataGridView1.CurrentRo w.Cells(0) Is Nothing andalso Not String.IsNullOrEmpty(Me.Da taGridView 1.CurrentR ow.Cells(0 ).Value) Then
Me.TextBox3.Text = Me.DataGridView1.CurrentRo w.Cells(0) .Value
End If
If Not Me.DataGridView1.CurrentRo
Me.TextBox3.Text = Me.DataGridView1.CurrentRo
End If
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks'
strickdd, sorry did not work...