我的程序界面有一个DataGridView,
当DataGridView内容刷新时,光标未做任何操作,直接在DataGridView中右健(有一个右键事菜单功能),
程序运行至
int i = 0;
i = (int)DataGridView.CurrentCell.RowIndex;
时,会提示:未将对象引用设置到对象的实例。
但是如果我先点一下左键,再点右键就没问题,这是什么原因?
------解决思路----------------------
int i = 0;
if(DataGridView.CurrentCell!=null)
{
i = (int)DataGridView.CurrentCell.RowIndex;
}
没点击的时候没有CurrentCell