views:

1996

answers:

3

I'm using the WPF DataGrid, and I'd like to know if there is any way I can access the DataGridRow's RowDetails programatically.

For example, when the user selects the row, I'd to grab some data from somewhere (say, a database), and display it in the RowDetails.

All of the examples I've seen tend to just display some extra bound data that isn't included in the columns for the row.

+1  A: 

You could display some extra data but lazy-load it on SelectionChanged.

It usually is not easy to work directly with the WPF controls, they are not really meant to be used without a backing databound model.

Denis Troller
I totally missed the fact that the DataGrid.LoadingRowDetails event hands you row details section as a framework element (in DataGridRowDetailsEventArgs.DetailsElement). This allowed me to add some code to do what I need.
David Allen
A: 

If you have all the data in list of objects (or something similar) then you can do all sorts of fun things. I'm using a WPF Datagrid in this manner, and when a user selects a row, I think populate an editor control above the grid with the row item plus additional details.

That said, there's nothing stopping you from adding in additional information in the grid that's normally hidden and a trigger on row selection to show the additional data

Stephen Wrighton
A: 

you can use the following code

DataRowView row = (DataRowView)MyDataGrid.SelectedItem; string strName = row.Row["Name"].ToString(); //where "Name" is the column name