当前位置: 代码迷 >> C# >> DataGridView.CurrentCell.RowIndex出错
  详细解决方案

DataGridView.CurrentCell.RowIndex出错

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

没点击的时候没有CurrentCell
  相关解决方案