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

Getting Cell Values in Radgrid - URGENT HELP RQD.

1 Answer 108 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Abdul Kadar
Top achievements
Rank 1
Abdul Kadar asked on 03 Jul 2010, 04:00 PM
hi,

I have a radgridview.While clicking on the cells, I got the values in a radlabel as shown below.
But I got the error ,"Object reference not set to an instance of an object " when clicking on the gridview header or some other places in the radgridview.How can i avoid this error.

Private Sub RadGridView1_CellClick(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellClick

 

 

 

RadLabel5.Text =

 

"Selected S.No :" & e.Row.Cells("serialno").Value & " - " & e.Row.Cells("name").Value.ToString

 

1 Answer, 1 is accepted

Sort by
0
Boryana
Telerik team
answered on 07 Jul 2010, 12:44 PM
Hello Abdul Kadar,

Thank you for contacting us.

In your case I suggest to handle the CurrentCellChanged event. It is important to make sure that the current cell is not null. Please have a look at the following snippet:

Private Sub RadGridView1_CurrentCellChanged(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CurrentCellChangedEventArgs) Handles RadGridView1.CurrentCellChanged
    If e.NewCell IsNot Nothing Then
        Me.RadLabel1.Text = e.NewCell.Text
    End If
End Sub

However, if you insist to use the CellClick event, you should check whether the cell is of type GridDataCellElement.

Private Sub RadGridView1_CellClick(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellClick
    If TypeOf sender Is GridDataCellElement Then
       Me.RadLabel1.Text = e.Value.ToString()
    End If
End Sub

I hope this is helpful. Let me know if I can assist you further.

Sincerely yours,
Boryana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Abdul Kadar
Top achievements
Rank 1
Answers by
Boryana
Telerik team
Share this question
or