3

I'm using the WPF toolkit DataGrid.

How can I get the values of the cells of the selected rows?

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Jonathan
  • 11,809
  • 5
  • 57
  • 91

1 Answers1

8

In WPF rows represent objects in a list and columns are object's properties.

It depends on what DataGrid.ItemsSource is.If your ItemSource is an array of BindedClass you could get selected object by:

BoundClass bc = (BoundClass)dataGridControl.SelectedItem;
var prop1 = bc.Prop1;
var prop2 = bc.Prop2;
Felix D.
  • 4,811
  • 8
  • 38
  • 72
Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184
  • Ok, I got it. The problem was that I retrieve the info from the DB using Linq, and I did it using anonymous types. But you gave me the clue to find my mistake explaining me how the datagrid works. Thanks! – Jonathan Oct 15 '09 at 11:28