Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a datagrid which contains a datagridCombobox column in windows form application. The problem is when the combobox value is changed it doesn't throw any exception when the form is loaded. But when a dialog box is opened & closed for changing the value of other cell and tried to change the selection in datagridcombobox column it throws stack overflow exception. When checked using stack trace it shows databinding event being triggered multiple times. Datagrid being used is very old version.

1st time when the grid is loaded & if i try changing the values binding even is not triggered, only after a dialog box is opened & closed such error occurs.

What I have tried:

int Columnindex = GetColumnIndex(columnName + "New");
                            DataGridViewComboBoxCell ComboBoxCell2 = new DataGridViewComboBoxCell();
                            ComboBoxCell2.DataSource = null;
                            ComboBoxCell2.DataSource = filteredOptions;
                            ComboBoxCell2.DisplayMember = ComboboxColumn.DisplayMember;
                            ComboBoxCell2.ValueMember = ComboboxColumn.ValueMember;
                            ComboBoxCell2.FlatStyle = FlatStyle.Flat;
                            ComboBoxCell2.DropDownWidth = 250;//shreyasimportant
                            this.gdbgGrid[Columnindex, gdbgGrid.CurrentCell.RowIndex] = ComboBoxCell2;
                            ComboBoxCell2.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;

                            System.Diagnostics.Debug.WriteLine("UTConfig - Step - setComboBoxBasicFilteredType()    ComboboxCellValue" + ComboBoxCell2.DisplayMember.ToString() + "  value is-  :: " + ComboBoxCell2.Value.ToString() + "" + gdbgGrid.Name);

                            if (m_ComboDirtyStateChanged) 
                                if (columnName != "Revision") 
                                    ComboBoxCell2.Value = Convert.ToString(filteredOptions[0][ComboboxColumn.DisplayMember]); //Commenting this line of code eliminates stack overflow exception & value is hidden in the combobox cell. Clicking the combobox cell the value appears.Need an alternative way to display the value.

                            System.Diagnostics.Debug.WriteLine("UTConfig - Step8 - setComboBoxBasicFiltered() - column exists- end  :: " + gdbgGrid.Name);
Updated 12-Mar-17 20:34pm

1 solution

We can't tell from that snippet exactly what is causing the problem - and even with the full project we probably couldn't either as we have no access to your data. Unfortunately, this kind of problem needs to be investigated while the code is running, which we cannot do. So it's going to be pretty much up to you.

Let's start by explaining what a Stack Overflow exception is caused by: recursion, either deliberate or accidental. When a method either directly or indirectly causes the method to be executed again. This can happen accidentally when an event handler makes a change which causes the event to be fired again before the handler has completed (though in most cases you need to use DoEvents to make it happen there are events where it can happen "naturally").

So start with the debugger, and look at the stack trace when the exception is fired. What's your code doing? Which method is recursing? The trace will give you a method name, file, and line number so that's fairly easy. Put a break point there and run it again. Follow the code through, and you should start to see where it's recursing, and hopefully why.
Sorry, but we can't do any of that for you!
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