尝试删除dataGridView中的行 [英] try to delete the row in dataGridView
本文介绍了尝试删除dataGridView中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图删除dataGridView中的行但是我得到了这个异常
对象引用未设置为对象的实例。
我的代码是:
Hi,
I am trying to delete a rows in dataGridView but i am getting this exception
Object reference not set to an instance of an object.
My Code is:
for (int AppiLib_Count = 0; AppiLib_Count < AppiLib.Count-1; AppiLib_Count++)
{
//Validating the Selected Row in DataGridView
if (dataGrid.SelectedRows.Count > 0)
{
//Deleting the Row on Macro Collapse
dataGrid.Rows[dataGrid.SelectedRows[0].Index].Selected = true;
dataGrid.Rows.Remove(dataGrid.Rows[dataGrid.SelectedRows[0].Index]);
}
}
请帮助..
Please help..
推荐答案
您无法删除所选行。
尝试:
you can not delete selected rows.
try:
for (int AppiLib_Count = 0; AppiLib_Count < AppiLib.Count-1; AppiLib_Count++)
{
//Validating the Selected Row in DataGridView
if (dataGrid.SelectedRows.Count > 0)
{
//Deleting the Row on Macro Collapse
dataGrid.Rows[dataGrid.SelectedRows[0].Index].Selected = false;
dataGrid.Rows.Remove(dataGrid.Rows[dataGrid.SelectedRows[0].Index]);
}
}
这篇关于尝试删除dataGridView中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文