Click here to Skip to main content
15,117,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I need some help retrieving cell data from a selected row of a wpf datagrid and I have no idea on how to achieve this. Please, can someone help me figure this out? Possibly post an example as well if you know how to get the data.

Thanks in advance!!
Updated 23-Aug-20 2:09am

I think this answer by Bigsby[^] might help you.
Member 13116441 8-Jul-18 11:12am
This worked like a charm! thanks.

var person = grid.SelectedItem as Person;
if (person != null) textBlock.Text = person.FirstName;
These code works if you put the SelectionUnit property in FullRow.

private void GetSelectedRowCellValue()
    foreach (DataGridRow row in dataGrid1.SelectedItems)
         System.Data.DataRow MyRow = (System.Data.DataRow)row.Item;
         string value = MyRow["columnname"].ToString();
This thread goes way back, but if someone new stumbles upon this situation this might help:

In addition to what 'adocas' said, which was not working for me because of conversion between DataGridRow & DataRow not working, I came up this solution:

private void yourDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    foreach (DataRowView row in yourDataGrid.SelectedItems)
        System.Data.DataRow MyRow = row.Row;
        string value = MyRow["columnname" (or index)].ToString();
        //MessageBox.Show(value); <- To check if it works...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900