Get values of the selected row

3 posts, 1 answers
  1. Harald
    Harald avatar
    79 posts
    Member since:
    Oct 2013

    Posted 01 Mar 2015 Link to this post

    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. Harald
    Harald avatar
    79 posts
    Member since:
    Oct 2013

    Posted 01 Mar 2015 Link to this post

    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?
  3. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Mar 2015 Link to this post

    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.

     
Back to Top