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

[Solved] Datakey for grid

3 Answers 109 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
josh
Top achievements
Rank 1
josh asked on 17 May 2013, 05:42 PM
I am using a RadDataGrid to show a grid of employees. How do I save the employee_id as the datakey, and then use that datakey to perform functions in my code behind when an employee is selected

3 Answers, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 18 May 2013, 03:41 PM
Hello Josh,

Thank you for your interest.

You can get the selected item or items through the RadDataGrid.SelectedItem and the RadDataGrid.SelectedItems properties. Depending on the current RadDataGrid.SelectionUnit(Cell or Row), the received value would be of type DataGridCellInfo or object(or respectively collections of these types). From the DataGridCellInfo class you can also access the corresponding object through the Item property. Thus, you can get all the needed information.
For more reference you can check the following help article - http://www.telerik.com/help/windows-8-xaml/raddatagrid-selection.html.

Let me know if this helps.

Greetings,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
josh
Top achievements
Rank 1
answered on 20 May 2013, 01:49 PM
Ivaylo, Thanks for your response. However I am still having issues...I have the SelectionUnit  to "Cell" for now. Here is my selection chambed method. What am I doing wrong?

private void radGridPatients_SelectionChanged_2(object sender, Telerik.UI.Xaml.Controls.Grid.DataGridSelectionChangedEventArgs e)

{

Telerik.UI.Xaml.Controls.Grid.DataGridCellInfo cI = (Telerik.UI.Xaml.Controls.Grid.DataGridCellInfo)radGridPatients.SelectedItem ;

Label1.Text = cI.Item.ToString();

}

0
Ivaylo Gergov
Telerik team
answered on 22 May 2013, 12:00 PM
Hi Josh,

For your convenience, I have attached a project that shows how get and ID that is associated with the selected item in the RadDataGrid. 

I hope this helps. Feel free to contact us if you have any other questions.

Regards,
Ivaylo Gergov
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Grid for XAML
Asked by
josh
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
josh
Top achievements
Rank 1
Share this question
or