How can I get the contents of a cell in a grid in C #?

I need to get the contents of a cell in a Grid in C #. Is there a way to do something like this?

 UIElement element = MyGrid.Children.getElementAt(x, y) 
+4
source share
1 answer

You can use Linq:

 // using System.Linq; var element = grid.Children.Cast<UIElement>(). FirstOrDefault(e => Grid.GetColumn(e) == x && Grid.GetRow(e) == y); 

or if the specified cell contains more than one element:

 var elements = grid.Children.Cast<UIElement>(). Where(e => Grid.GetColumn(e) == x && Grid.GetRow(e) == y); 

where the elements are IEnumerable<UIElement> .

+11
source

All Articles