2010-08-11 157 views
0

我有一個網格控件(而不是DataGrid),並且我想要刪除網格的內容。第二行中的第二列。這可以在沒有參考網格單元的內容的情況下完成嗎?清除網格單元格

非常感謝您的任何提示!

回答

4

找到更穩定的解決方案,但它需要通過細胞循環:

 // 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; 
      } 
+0

非常感謝,對我感到羞恥我沒有得到這個。正在拼命尋找某物。像網格[2] [5] ;-) – 2010-08-11 18:19:36

0

在代碼隱藏中,我想?

如果他們是爲了申報並填寫了所有字段,你可以得到的細胞數量

int cellNumber = rowNumber * columnCount + columnNumber; 

然後myGrid.Children[cellNumber-1]給你你想要的子節點。

myGrid.Children.RemoveAt(ellNumber-1);將從網格中刪除該子節點。

請注意,它只能從網格的子級列表中刪除。如果你有任何其他的參考資料,你也必須照顧他們。

+0

對不起,我才意識到我的回答並沒有真正解決問題。該解決方案僅適用於所有單元格按從左到右 - >從上到下的順序聲明。 – 2010-08-11 07:44:14

相關問題