Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit How to retrieve an item inside a DataGridRow
4 replies. Latest Post by Ors84bs on June 26, 2009.
(0)
Ors84bs
Member
30 points
85 Posts
06-24-2009 10:22 AM |
Hi,
i'd like to get the item contained inside a particular row of a silverlight datagrid.
How could I do?
Thank you very much
tanmoy.r
Contributor
3580 points
708 Posts
06-24-2009 10:55 AM |
MyClass item = MyDataGrid.ItemsSource.Cast<MyClass>().Where((_, pos) => pos == row_number).SingleOrDefault();
You might need to add System.Linq; namespace.
Brian Br...
326 points
60 Posts
06-24-2009 12:50 PM |
If you want the nth item inside the DataGrid, then you can grab it from the ItemsSource as suggested above. If you have an actual DataGridRow element, though, you can get the associated item from its DataContext.
yifung
3257 points
537 Posts
06-24-2009 7:01 PM |
Also, if you have an element within a Row, like a button, and you're using Silverlight 3, you can call the new static method DataGridRow.GetRowContainingElement. This method is in the newer builds of Silverlight 3, and I do not believe it is in the Beta build of Silverlight 3.
06-26-2009 4:02 AM |
You solved my problem