堆栈溢出异常。 [英] Stack overflow exception.

查看:108
本文介绍了堆栈溢出异常。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个数据网格,其中包含windows窗体应用程序中的datagridCombobox列。问题是当组合框值被更改时,它在加载表单时不会抛出任何异常。但是当打开一个对话框时&关闭以更改其他单元格的值并尝试更改datagridcombobox列中的选择它会引发堆栈溢出异常。使用堆栈跟踪检查时,它会显示多次触发数据绑定事件。正在使用的Datagrid是非常旧的版本。



第一次加载网格时&如果我尝试更改值绑定,即使没有触发,只有在打开一个对话框之后&关闭这样的错误。



我尝试了什么:



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);

推荐答案

我们无法从该片段确切地知道导致问题的原因 - 即使是完整的项目,我们也许不能我们无法访问您的数据。不幸的是,在代码运行时需要调查这种问题,这是我们无法做到的。所以这将取决于你。



让我们首先解释一下Stack Overflow异常是由什么造成的:递归,无论是故意的还是偶然的。当方法直接或间接导致该方法再次执行时。当事件处理程序进行更改导致事件在处理程序完成之前再次触发时,这可能会意外发生(尽管在大多数情况下,您需要使用DoEvents来实现它可以自然地发生的事件)。



所以从调试器开始,在触发异常时查看堆栈跟踪。你的代码在做什么?哪种方法递归?跟踪将为您提供方法名称,文件和行号,以便相当容易。在那里放一个断点并再次运行它。按照代码进行操作,你应该开始看看它在哪里递归,希望是为什么。

抱歉,我们不能为你做任何事情!
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!


这篇关于堆栈溢出异常。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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