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

How does one get row data from a DataGrid?

3 Answers 50 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 27 May 2011, 03:34 PM
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?

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 27 May 2011, 03:38 PM
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
0
William
Top achievements
Rank 1
answered on 27 May 2011, 04:01 PM
So I just use the column name?
0
William
Top achievements
Rank 1
answered on 27 May 2011, 06:45 PM
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;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Tags
General Discussions
Asked by
William
Top achievements
Rank 1
Answers by
Vlad
Telerik team
William
Top achievements
Rank 1
Share this question
or