![](/img/trans.png)
[英]How to set the pointer to the current row in the Datagridview in C#
[英]How to empty the current row of a DataGridView in C#?
您將需要在數據網格中指定要刪除的行。 您可以通過選擇所選行的“索引”來實現。
dataGrid.Rows[index].Selected = true;
或者您可以執行以下操作:
dataGrid.SelectedRows.Clear();
foreach(DataGridViewRow row in dataGrid.Rows)
{
if(YOUR CONDITION)
row.Selected = true;
}
我總是使用removeat,首先檢查以確保已選中某些內容,然后在傳遞索引的同時執行removeat。
if(dataGridView1.CurrentRow.Index > -1 && !dataGridView1.Rows[dataGridView1.CurrentRow.Index].IsNewRow)
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
編輯:在AllowUsersToAddRows為True的情況下添加了對IsNewRow的檢查,如果這是所選行,則會拋出異常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.