【发布时间】:2017-01-27 05:03:14
【问题描述】:
当我更改单元格值以进行更新并直接单击菜单条项以打开新的 Winform 时,抛出 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
}
}
异常 - 操作无效,因为它会导致 可重入调用 SetCurrentCellAddressCore 函数。
在 System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex,Int32 rowIndex,布尔值 setAnchorCellAddress,布尔值 validateCurrentCell, Boolean throughMouseClick) 在 System.Windows.Forms.DataGridView.set_CurrentCell(DataGridViewCell 值)在 System.Windows.Forms.DataGridView.set_DataSource(对象 值)
【问题讨论】:
-
你试过这个代码
private void dgv_category_CellEndEdit(object sender, DataGridViewCellEventArgs e) { this.BeginInvoke(new MethodInvoker(() => } -
@GovindTupkar 是的,我试过了,但没用...
-
您尝试过 CellLeave 事件或 CellValidating 事件吗?
-
@FakeisMe,是的,我也尝试过 CellLeave 事件和 CellValidating 事件。
标签: c# .net winforms datagridview invalidoperationexception