David Allen
David Allen

Reputation: 13

WPF DataGrid - Setting RowDetails programmatically

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.

Upvotes: 0

Views: 3773

Answers (3)

Subalakshmi
Subalakshmi

Reputation:

you can use the following code

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

Upvotes: 0

Stephen Wrighton
Stephen Wrighton

Reputation: 37840

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

Upvotes: 0

Denis Troller
Denis Troller

Reputation: 7501

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.

Upvotes: 1

Related Questions