调用dataGridView1_CellEndEdit编辑方法重新绑定数据,则会提示操作无效,原因是它导致对 SetCurrentCellAddressCore 函数的可重入调用。
在网上查了一系列资料后也没有找到答案,后来干脆放弃了,用CellValueChanged事件来完成该功能,但发现还是报错,调试时发现第一次绑定数据的时候就执行了CellValueChanged事伯,后来我给了一个全局变量,第一次执行显示的时候不执行该操作成功解决问题,代码如下:
public void Bind()
        {
            dataGridView1.DataSource = new ArticleTypeServer().GetAll();
            postback = 1;//第一次已加成功加载
        }
       int postback = 0;//0表示第一次执行本窗口
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (postback != 0)//判断是否不是第一次执行本窗口
            {
                int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                string text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
                if (new ArticleTypeServer().Edit(id, text) == 0)
                {
                    MessageBox.Show("操作失败");
                    return;
                }
                Bind();
            }
        }
- 本文标题: 操作无效,原因是它导致对 SetCurrentCellAddressCore 函数的可重入调用。
- 文章分类:【WinForm/WPF】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
- 上一篇:Winfrom C#添加右键菜单
- 下一篇: asp.net 读取,写入记事本操作