RadGridView CurrentRowChanged blows up form

5 posts, 0 answers
  1. Bkoenig
    Bkoenig avatar
    11 posts
    Member since:
    Jun 2013

    Posted 12 Jul 2013 Link to this post

    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.
  2. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 17 Jul 2013 Link to this post

    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 >>
  3. Bkoenig
    Bkoenig avatar
    11 posts
    Member since:
    Jun 2013

    Posted 17 Jul 2013 Link to this post

    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
  4. Bkoenig
    Bkoenig avatar
    11 posts
    Member since:
    Jun 2013

    Posted 18 Jul 2013 Link to this post

    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
  5. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 19 Jul 2013 Link to this post

    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 >>
Back to Top