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

Get values of the selected row

2 Answers 192 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Harald
Top achievements
Rank 1
Harald asked on 01 Mar 2015, 08:50 AM
Hi I have a RadGridView. The ItemSource is a DataView based on a DataTable. The GridView Property AutoGenerateColumns = "False".

XAML:
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn x:Name="VisitNumber" DataMemberBinding="{Binding VisitNumber}" Header="Fallnummer" Width="120"/>
<telerik:GridViewDataColumn x:Name="LastName" DataMemberBinding="{Binding LastName}" Header="Nachname" Width="200"/>
<telerik:GridViewDataColumn x:Name="FirstName" DataMemberBinding="{Binding FirstName}" Header="Vorname" Width="150"/>
</telerik:RadGridView.Columns>

How can I retrieve the values of the selected row using C # code?

2 Answers, 1 is accepted

Sort by
0
Harald
Top achievements
Rank 1
answered on 01 Mar 2015, 09:27 AM
After some tests, I found the following solution:

C#:
System.Data.DataRowView CurrentSelected = ((System.Data.DataRowView)MyGridView.SelectedItem); 
MessageBox.Show(Convert.ToString(CurrentSelected.Row.ItemArray[1]));

Is this the right way to do this?
0
Accepted
Maya
Telerik team
answered on 02 Mar 2015, 07:08 AM
Hi Harald,

Working with SelectedItem property and casting it to the correct type is the way to go. 

Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Harald
Top achievements
Rank 1
Answers by
Harald
Top achievements
Rank 1
Maya
Telerik team
Share this question
or