Get the data from a row
This article shows how to obtain the data from a row of RadGridView.
We will consider two scenarios - getting the data from the selected row and getting the data from any GridViewRow.
- The SelectedItem property of RadGridView returns an object which can be cast to your business object. So, it is very easy to get the underlying data from the selected item:
private void Button1_Click(object sender, RoutedEventArgs e)
{
Club club = this.clubsGrid.SelectedItem as Club;
string message = string.Format("Name: {0} \n Established: {1} \n Capacity: {2}", club.Name,
club.Established,
club.StadiumCapacity);
MessageBox.Show(message);
}
Private Sub Button2_Click(sender As Object, e As RoutedEventArgs)
Dim club As Club = TryCast(Me.clubsGrid.SelectedItem, Club)
Dim message As String = String.Format("Name: {0} " & vbLf & " Established: {1} " & vbLf & " Capacity: {2}", club.Name, club.Established, club.StadiumCapacity)
MessageBox.Show(message)
End Sub
- Getting the data from an arbitrary GridViewRow is almost the same - you just need to cast its DataContext or Item property to your business object:
void clubsGrid_RowActivated(object sender, Telerik.Windows.Controls.GridView.RowEventArgs e)
{
var row = e.Row as GridViewRow;
Club club = row.Item as Club;
string message = string.Format("Name: {0} \n Established: {1} \n Capacity: {2}", club.Name,
club.Established,
club.StadiumCapacity);
MessageBox.Show(message);
}
Private Sub clubsGrid_RowActivated(sender As Object, e As Telerik.Windows.Controls.GridView.RowEventArgs)
Dim row = TryCast(e.Row, GridViewRow)
Dim club As Club = TryCast(row.Item, Club)
Dim message As String = String.Format("Name: {0} " & vbLf & " Established: {1} " & vbLf & " Capacity: {2}", club.Name, club.Established, club.StadiumCapacity)
MessageBox.Show(message)
End Sub