Link to home
Start Free TrialLog in
Avatar of bish wakim
bish wakim

asked on

How retrieve the content of a certain cell inside Wpf Grid

I have a Grid which contains 2 Rows and 10 coulumns. In each cell of this grid there is a textbox control. how can i retrieve dynamically the text  of a certain textbox  by giving his row an column numbers?
thanks
Avatar of CuteBug
CuteBug
Flag of India image

try this code
public UIElement GetCell(Grid grid, int row, int col)
        {
            if (grid.Children.Count == 0)
                return null;

            UIElement result = null;

            try
            {
                result = (UIElement)grid.Children.Cast<UIElement>().First(e => (Grid.GetRow(e) == row) && (Grid.GetColumn(e) == col));
            }
            catch (InvalidOperationException)
            {

            }

            return result;
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CuteBug
CuteBug
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bish wakim
bish wakim

ASKER

Thanyou