开发者

Clear a grid cell

I have a Grid control (not a DataGrid) and I want to remove the content of e.g. the second column i开发者_如何学Cn the second row. Can this be done without having a reference to the content of a grid cell?

Thank you very much for any hint!


Found a more stable solution, though it requires looping through the cells:

        // these are the row and column number of the cell
        // you want to have removed...
        int getRow = 2, getCol = 5;
        for (int i = 0; i < myGrid.Children.Count; i++)
            if ((Grid.GetRow(myGrid.Children[i]) == getRow)
                && (Grid.GetColumn(myGrid.Children[i]) == getCol))
            {
                myGrid.Children.Remove(myGrid.Children[i]);
                break;
            }


In codebehind, I suppose?

If they are declared in order and all fields are filled, you can get the number of the cell by

int cellNumber = rowNumber * columnCount + columnNumber;

Then myGrid.Children[cellNumber-1] gives you the child node you want.

myGrid.Children.RemoveAt(ellNumber-1); would remove that child node from the grid.

Note though that it only gets removed from the grid's list of children. If you have any other references to that item, you must take care of them, too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜