Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

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.CurrentRow.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



 
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America 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
SOLUTION
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 Fordraiders

ASKER

shaun, worked fine...
Thanks'
strickdd, sorry did not work...
To expand on strickdd's comment, you may need to check each level to see if that object is null:

If Not Me.DataGridView1.CurrentRow Is Nothing andalso Not Me.DataGridView1.CurrentRow.Cells(0) Is Nothing andalso Not String.IsNullOrEmpty(Me.DataGridView1.CurrentRow.Cells(0).Value) Then
  Me.TextBox3.Text = Me.DataGridView1.CurrentRow.Cells(0).Value
End If
SOLUTION
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