how to get the control added at the specified row and column in window control Grid(not gridview or datagrid)? in C#
Suppose we know which row and column the control is located, how to get the control by grid row and column?
Thanks
how to get the control added at the specified row and column in window control Grid(not gridview or datagrid)? in C#
Suppose we know which row and column the control is located, how to get the control by grid row and column?
Thanks
Well, you could do this with a LINQ query easily enough:
public IEnumerable<UIElement> GetElementsAtPosition(Grid grid, int row, int column)
{
return grid.Children.OfType<UIElement>().Where(c => Grid.GetRow(c) == row && Grid.GetColumn(c) == column);
}
This needs to return an IEnumerable
, as there can be multiple controls at a given row & column intersection. This is also not very reliable if you are doing Row/Column spanning (it won't catch the case where an element starts at a different row or column, and spans into it).
EDIT Thanks @wpfwannabe for the proper LINQ operator required to make this work. It still boggles my mind that UIElementCollection doesn't implement IEnumerable<UIElement>.