This is a migrated thread and some comments may be shown as answers.

RadGridView CurrentRowChanged blows up form

4 Answers 248 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bkoenig
Top achievements
Rank 1
Bkoenig asked on 12 Jul 2013, 03:20 PM
Hello,

I can't seem to figure this error out.  When I add the code below to the code for my main form it will throw the exception "An error occurred creating the form. See Exception.InnerException for details.  The error is: Object reference not set to an instance of an object."

The form is to manage a series of applications I have been creating.  The grid view shows a list of banned users and allows for Editing of the records as well as showing them.  I have a few text boxes that act as a form so when a row is selected, data is shown there.
Private Sub Bans_Grid_CurrentRowChanged(sender As Object, e As Telerik.WinControls.UI.CurrentRowChangedEventArgs) Handles Bans_Grid.CurrentRowChanged
Bans_Name_txt.Text = e.CurrentRow.Cells.Item(3).Value.ToString  'It breaks on this line.
End Sub

I know its this line because if I comment it out the form loads perfectly fine.

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 17 Jul 2013, 06:50 AM
Hello Brendon,

Thank you for writing.

I am not sure how this code even compiles as the Cells property of the CurrentRow does not have Items property. The correct line would be:
Bans_Name_txt.Text = e.CurrentRow.Cells(3).Value.ToString()

If this is not the case, please provide me with a sample where I can reproduce the experienced exception and I will investigate the reasons causing it.

Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Bkoenig
Top achievements
Rank 1
answered on 17 Jul 2013, 12:36 PM
Hello Stefan,

Unfortunately I reworked my design to get rid of this form, but I will see if I can create a sample to assist in solving this problem.  It will take me some time with my current schedule however.

Also that code was written using Intellisense which said that it was a valid command.

Thank you,
Brendon
0
Bkoenig
Top achievements
Rank 1
answered on 18 Jul 2013, 01:07 PM
Hello,

I was able to create a test project and the error occurred on both .net 4.0 and .net 4.5 and with both my original code and your code.

A support ticket was placed to submit the solution with the ID 717125

Thank you
0
Stefan
Telerik team
answered on 19 Jul 2013, 11:01 AM
Hi,

I am copying my answer from the support thread so the community can benefit from it: 

As I mentioned, there is not Item property so this is why you are getting the exception. Also, you grid has no data in it, so it is expected to receive the exception you see. Once you populate it with data, here is the code you can use:

Private Sub Bans_Grid_CurrentRowChanged(sender As Object, e As Telerik.WinControls.UI.CurrentRowChangedEventArgs) Handles Bans_Grid.CurrentRowChanged
      If e.CurrentRow.Cells(3).Value IsNot Nothing Then
          Bans_Name_txt.Text = e.CurrentRow.Cells(3).Value.ToString()
      End If
  End Sub

The code above assumes that you have at least 4 columns in the grid, as it is trying to access the value of the fourth cell in the current row.
 
Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Bkoenig
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Bkoenig
Top achievements
Rank 1
Share this question
or