Can i reference to DataGridRow on DataGrid

Feb 18, 2009 at 7:11 AM
I want to know how to reference to DataGridRow on DataGrid like dg.Rows[index]. Can I do this on WPF Toolkit DataGrid?

Feb 18, 2009 at 7:40 AM
Hi Ek,

This will do the trick:


Not all that obvious is it?

The DataGrid is an ItemsControl (just like LiistView, ListBox etc ...), each ItemsControl has an associated ItemContainerGenerator which is responsible for generating the 'container' for your bounds data object. For the DataGrid, the container is a DataGridRow.

Have a look at the other methods on dg.ItemContainerGenerator, you might find them useful in the future.

Colin E.
-- - my WPF blog - WPF DataGrid Practical Examples

Feb 18, 2009 at 11:17 PM
I tried this, but when I attempted to pull off things like height, I got nothing.  Are there any other solutions?
Feb 18, 2009 at 11:35 PM
Thank you Colin, Did you have any suggestion book for WPF developer? (I have start half of WPF Unleashed)

Feb 19, 2009 at 7:40 AM
I have read a few WPF books and in my opinion WPF Unleashed is by far the best - so keep going with it!

Colin E.
Feb 19, 2009 at 2:46 PM
Colin, do you think you can give an example on how to do some direct DataGridRow manipulation?

Like this:

but that doesn't work...
Feb 19, 2009 at 4:09 PM
Resolved!  I found out that I needed to get the actual height, because Height is just a place holder to tell it what Height to set it at:

This does return the clicked row on this event:
private void SelectedRow(object sender, SelectionChangedEventArgs e)