Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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());
            }
        }
Posted
Updated 18-Jan-12 1:09am
v5
Comments
Can you post the total of your code? so that it will be easier to find out the problem.
Programm3r 18-Jan-12 7:22am    
Could you please post the stack trace as well as the code addressed within the trace (as mentioned in previous comment).
Sergey Alexandrovich Kryukov 18-Jan-12 20:55pm    
Agree, I always advised that. In my post, I explain how to work with exceptions in detail, please see.
--SA

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900