2012-10-11 38 views
0

在telerik radgrid中,我想刪除網格的第4行,但它不工作。它會拋出錯誤Argument out of exceptionTelerik radgrid無法刪除空行

我得到4行,前2行有一些值...所以我想刪除其他2行是空的,但它不工作。

嘗試1:

radGridView2.Rows.Remove(radGridView2.Rows[3]); 

嘗試2:

radGridView1.Rows.RemoveAt(3); 

的radgrid控件代碼:

private const int Test = 4; 
private void SetDataGridView() 
     { 


      for (var rowCount = 0; rowCount < Test; rowCount++) 
      { 
       radGridView1.Rows.Add(string.Empty); 


      } 
     } 

回答

1

你可以嘗試從數據源中刪除它,然後才能調用數據綁定綁定新的數據源。

刪除的數據表

YourDataTable.Rows.Remove(YourRow); 

所以,你可以在去除被執行,添加一塊手錶看電網多少行的行前行右側與

int count = YourControl.Rows.Count; 
for (int i = 0; i <= count; i++) 
{ 
    if (condition) //You can adjust your condition, for example i == 0 
    { 
     YourControl.DeleteRow(i); 
    } 
} 
+0

我沒有使用任何數據源。 – linguini

+0

我在控制位置用DeleteRow –

+0

更新了我的帖子,我把'radGridView2'它不接受。它顯示我一個錯誤;你能告訴我什麼是條件。謝謝 – linguini

0

創建。 我認爲你的代碼做了更多的事情,這個問題的片段中沒有顯示。

+0

我已經添加了radgrid代碼。 – linguini

0

remove從radgrid控件在winform C#中的所有行

for (int totalrow = 0; totalrow < radGridView1.Rows.Count; totalrow++) 
{ 
    radGridView1.Rows.RemoveAt(0); 
    totalrow--; 
}