How does one get row data from a DataGrid?

4 posts, 0 answers
  1. William
    William avatar
    14 posts
    Member since:
    Jan 2010

    Posted 27 May 2011 Link to this post

    How does one get row data from a DataGrid?
     I have gotten this far:
     
    DataGridRow item = (DataGridRow)dg.SelectedItem;
     
    Now how do I get the individual components of the item that I guess is the selected row?
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 27 May 2011 Link to this post

    Hello,

     You can cast SelectedItem to your data item type and access any property. For example:

    var customer = (Customer)dg.SelectedItem;

    Greetings,
    Vlad
    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
  3. William
    William avatar
    14 posts
    Member since:
    Jan 2010

    Posted 27 May 2011 Link to this post

    So I just use the column name?
  4. William
    William avatar
    14 posts
    Member since:
    Jan 2010

    Posted 27 May 2011 Link to this post

    This does not seem to work.

    The data that is put into the datagrid is from the following class:

     

     

    public class

    Data

     

     

    {

     

    public string FirstName { get; set; }

    public string LastName { get; set; }

     

    public int Age { get; set; }
    public bool Available { get; set; }

    public int index_1 { get; set; }

     

    public int index_2 { get; set; }

     

    public int index_3 { get; set; }

     

    public int index_4 { get; set; }

    public int index_5 { get; set; }

     

    public int index_6 { get; set; }

    public int index_7 { get; set; }

     

    public int index_8 { get; set; }

     

    public int index_9 { get; set; }

     

    public int index_10 { get; set; }

     

    public int index_11 { get; set; }
    public int index_12 { get; set; }
    public int index_13 { get; set; }
    public int index_14 { get; set; }
    public int index_15 { get; set; }

    }


    But when I try to read the row of data, none of these techniques work:

     

     

     

     

    var info = (

     

    DataGridRow.index_1)dg.SelectedItem;

     

     

    info = (Data .index_1)dg.SelectedItem;

     

     

    info = (index_1)dg.SelectedItem;

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

Back to Top