数据Gridview:无效的操作异常 [英] Data Gridview: Invalid Operation Exception

查看:78
本文介绍了数据Gridview:无效的操作异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用网格视图:我需要通过数据网格视图进行更新:我的第一列需要作为数据网格视图组合框列单元格:在第一列单元格中单击此后,我正在从数据库填充数据我将文本框列转换为组合框单元格并为此填充数据.在第二行第一列中单击,我得到了无效操作单元格提供程序已属于网格视图的异常:如何解决此问题:

这是我的编码:

I am using grid view in my project : i need to update through data grid view :My first column i need as data grid view combo box column cell: I am filling data from data base after that during first column cells click i am converting text box column as combo box cell and filling data for that.During second row first column click i am getting Invalid operation cell provider already belongs to the grid view Exception :how to solve this problem:

This is my coding:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {           
            DataGridViewComboBoxCell dd1 = new DataGridViewComboBoxCell();   
            try
            {
                if (e.ColumnIndex == 0)
                {
                    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] = dd1;
                    getcom(); \\it is for fill data to combo box from database                     
                }
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

推荐答案

您已经捕获了正确的异常.好,现在,使用Exception.Stack查看整个堆栈.另外,使用调试器找出问题所在.您可以快速找出问题所在.

为了将来,不要在本地捕获异常.在每个线程堆栈的顶部捕获所有异常(不仅是这种类型的异常).另外,您需要在主UI周期的最顶部捕获所有异常. WPF和System.Windows.Forms中都有专门的机制.

有关此主题的更多详细信息,请参阅我过去的解决方案,在其中对其进行详细说明:
我如何制作滚动条到达底部时将停止的循环 [当我运行应用程序时,例外是捕获了如何处理此问题? [扔. .then ... rethrowing [ ^ ],
错误记录和屏幕截图. [捕获异常 [
You already caught the right exception. Good, now, use Exception.Stack to see the whole stack. Also, use the debugger to find out what''s going wrong. You can dig out the problem pretty fast.

For future, don''t catch exceptions locally. Catch all exceptions (not just of this type) on the very top of the stack of each thread. Also, you need to catch all exception on the very top inside the main UI cycle. There are special mechanisms for that in both WPF and System.Windows.Forms.

For further detail on this topic, please see my past solution where I explain it in detail:
How do i make a loop that will stop when a scrollbar reaches the bottom[^].

Some other related solutions I explain other related details:
When i run an application an exception is caught how to handle this?[^],
throw . .then ... rethrowing[^],
Error Logging and Screen Shot.[^],
Catching an Exception[^].

Sorry, some text is repeated in different posts, but you will find what you need.

—SA


这篇关于数据Gridview:无效的操作异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆