none
An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll

    Question

  • Hi,

       I'm working on a n-tier Windows Application. I'm using ComboBox and populate it with patient names. I'm using a method declared in  the BLL. Simply the code follows like below.

     

    cboPatientName.DataSource = admissions.GetNonAdmittedPatients();

    cboPatientName.DisplayMember = "Name";

    cboPatientName.ValueMember = "ID";

    cboPatientName.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

    cboPatientName.AutoCompleteSource = AutoCompleteSource.ListItems;

    cboPatientName.DropDownStyle = ComboBoxStyle.DropDown;

    cboPatientName.Text = "";

     

    When I complies it displays 'Build Successful'.

     

    But in Runtime when I start typing in the combo box an exception "An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll" is raising.

     

    I didn't understand what's going behind.

     

    Plz help me getting on this. B'coz my application consists a lot of combobox like this.

     

    Advanced thanks.

     

    With regards,

    SreeRam.

     

    Monday, February 18, 2008 2:00 PM

Answers

  •  

    Hi SreeRam,

    I cannot reproduce your problem with the following testing code.

    Code Snippet

    namespace CBO

    {

        public partial class BindingToBusinessObject : Form

        {

            public BindingToBusinessObject()

            {

                InitializeComponent();

            }

     

            private void BindingToBusinessObject_Load(object sender, EventArgs e)

            {

                BindingList<BusinessObject> list = new BindingList<BusinessObject>();

                for (int i = 1; i < 50; i++)

                {

                    BusinessObject obj = new BusinessObject();

                    obj.Id = i;

                    obj.Name = i.ToString("00") + "name";

                    list.Add(obj);

                }

               

                this.comboBox1.DisplayMember = "Name";

                this.comboBox1.ValueMember = "Id";

                this.comboBox1.DataSource = list;

                this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

                this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;

                this.comboBox1.DropDownStyle = ComboBoxStyle.DropDown;

                this.comboBox1.SelectedIndex = -1;

     

            }

        }

     

        class BusinessObject

        {

            int id;

     

            public int Id

            {

                get { return id; }

                set { id = value; }

            }

     

            string name;

     

            public string Name

            {

                get { return name; }

                set { name = value; }

            }

        }

    }

     

    As the error said, this exception is thrown when the execution stack overflows by having too many nested method calls. In your case, you problem bind some other properties (like the Text, SelectedValue ect.) of the ComboBox to other objects. Please check if you have done this.

    More information, please visit:
    http://msdn2.microsoft.com/en-us/library/w6sxk224(VS.80).aspx

    Let me know if this helps. If not, could you please provided more information about how you bind your ComboBox?

    Best regards.
    Rong-Chun Zhang

    Friday, February 22, 2008 8:16 AM

All replies

  •  

    Hi SreeRam,

    I cannot reproduce your problem with the following testing code.

    Code Snippet

    namespace CBO

    {

        public partial class BindingToBusinessObject : Form

        {

            public BindingToBusinessObject()

            {

                InitializeComponent();

            }

     

            private void BindingToBusinessObject_Load(object sender, EventArgs e)

            {

                BindingList<BusinessObject> list = new BindingList<BusinessObject>();

                for (int i = 1; i < 50; i++)

                {

                    BusinessObject obj = new BusinessObject();

                    obj.Id = i;

                    obj.Name = i.ToString("00") + "name";

                    list.Add(obj);

                }

               

                this.comboBox1.DisplayMember = "Name";

                this.comboBox1.ValueMember = "Id";

                this.comboBox1.DataSource = list;

                this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

                this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;

                this.comboBox1.DropDownStyle = ComboBoxStyle.DropDown;

                this.comboBox1.SelectedIndex = -1;

     

            }

        }

     

        class BusinessObject

        {

            int id;

     

            public int Id

            {

                get { return id; }

                set { id = value; }

            }

     

            string name;

     

            public string Name

            {

                get { return name; }

                set { name = value; }

            }

        }

    }

     

    As the error said, this exception is thrown when the execution stack overflows by having too many nested method calls. In your case, you problem bind some other properties (like the Text, SelectedValue ect.) of the ComboBox to other objects. Please check if you have done this.

    More information, please visit:
    http://msdn2.microsoft.com/en-us/library/w6sxk224(VS.80).aspx

    Let me know if this helps. If not, could you please provided more information about how you bind your ComboBox?

    Best regards.
    Rong-Chun Zhang

    Friday, February 22, 2008 8:16 AM
  • Actually what is happening is I have nearly 3000 records in my table. I'm binding the combobox with the GetPatientNames() method written in my Patients.cs (BLL) file. In that method I'm only retriving the ID and name of the Patients especially for binding purpose.

     

    While running my application I'm start typing in the combobox. According to the AutoCompleteMode property it is displaying the names starting with the letters i've typed. When the no of letters exceeds 3 or 4 or when i tried to remove all letters and start typing from first letter my application is crashing. I've to find out the reason why this is happening. And one more thing that I tried was I deleted all the records and tried it with below 100 records the result is same. And I also cross checked whether there is any recurrsive loops that I had misplaced.

     

    I have to unpack it.

    Friday, February 22, 2008 2:45 PM
  • perhaps you should return

    cboPatientName.DataSource = admissions.GetNonAdmittedPatients().ToList();

    or returning List as your return type.



    Brainstorm your Brain and find solution,if no result stuck to Brainstormer.
    Thursday, October 06, 2011 10:37 AM
  • Remove all of the Event handlers from the ComboBox and see if the problem still happens.

    Chances are that it won't.

    My guess would be that something in [usually] the SelectedIndexChanged event is doing "something" that manipulates the ComboBox but that while the binding is still going on, it upsets things just a little. 

     


    Regards, Phill W.
    Thursday, October 06, 2011 12:46 PM