抛出InvalidOperationException
当我更改单元格值更新并直接单击菜单条项目打开新的Winform。因为它会导致 折返调用SetCurrentCellAddressCore功能数据网格视图CellValueChanged事件抛出InvalidOperationException
private void dgv_category_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
DataTable dt = new DataTable();
dt = u.operationOnDataBase(sqlquery_selectCategory, 3);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Category Already Exist...");
}
else
{
u.operationOnDataBase(sqlquery_UpdateCategory, 1);
u.SyncMaster("update", "CategoryDetails", 0, Convert.ToInt32(dgv_category[1, e.RowIndex].Value.ToString()));//---------Sync
}
try
{
dgv_category.DataSource = null; //here Throwing exception
u.operationOnDataBase(sqlquery, 3);
dgv_category.DataSource = u.dt;
}
catch (InvalidOperationException)
{
// exception
}
}
Exception-操作无效。
在System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(的Int32 columnIndex,的Int32 rowIndex位置,布尔setAnchorCellAddress,布尔 validateCurrentCell,布尔throughMouseClick)在 System.Windows.Forms.DataGridView.set_CurrentCell在系统(的DataGridViewCell 值) .Windows.Forms.DataGridView.set_DataSource(对象 值)
难道ü尝试这个代码 '私人无效dgv_category_CellEndEdit(对象发件人,DataGridViewCellEventArgs E) { this.BeginInvoke(新MethodInvoker( ()=> }' –
@GovindTupkar是的,我试过这个,但没有工作... –
你试过CellLeave事件还是CellValidating事件? – FakeisMe