Solved

Combo-box crashing Win-forms C# app

Posted on 2010-11-09
6
362 Views
Last Modified: 2013-12-17
Application data source is an Entity Framework. The Combo-box is bound to the data using a bindingSource control and when I attempt to exit the application the combo-box goes blank and the application hangs. It doesnt close and no further mouse clicks are accepted.

Interestingly I see that the SelectedIndexChanged event happens multiple times when I move between records using the navigator even when I dont change the combo box and it seems as if something happens to the combo box as I attempt to close the app using the red top right hand x.

There is no other code other than what you see attached and what is generated by VS2010.
namespace Sales

{

    public partial class frmMain : Form

    {

        public frmMain()

        {

            InitializeComponent();

        }



        private void frmMain_Load(object sender, EventArgs e)

        {

            GetCustomers();

        }



        private void GetCustomers()

        {

            var myData = new IIAAModel.IIAAEntities();

            var customerQuery = from c in myData.tblCustomers

                                select c;



            tblCustomerBindingSource.DataSource = customerQuery.ToList();

            

        }

        

        /*private void GetOneCustomer(int CustomerID) 

        {

            var myData = new IIAAModel.IIAAEntities();

            var customerQuery = from c in myData.tblCustomers

                                where c.lngCustomerID == CustomerID

                                select c;

                               

            tblCustomerBindingSource.DataSource=customerQuery.ToList();





        }*/

        private void cboAccountNumber_SelectedIndexChanged(object sender, EventArgs e)

        {

            //GetOneCustomer(cboAccountNumber.SelectedIndex);



            try

            {

                MessageBox.Show("cbo Changed");

            }

            catch (Exception ex)

            {

                

                MessageBox.Show(ex.Message);

            }

        }



    }

}

Open in new window

0
Comment
Question by:Adapt2NL
  • 4
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
rogerard earned 500 total points
ID: 34097264
in the form's onclose event, try setting the combobox datasource to no nothing
0
 

Author Comment

by:Adapt2NL
ID: 34097316
Do you have any idea why the SelectedIndexChanged keeps reoccurring?
0
 
LVL 7

Expert Comment

by:rogerard
ID: 34097342
Sorry, no.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Adapt2NL
ID: 34101489
It works well on the close form event. However, the proble also occurs when moving from record to record using the navigation control.

What is the root cause of the issue? Is there a standard way of using combo boxes to move to records that match the ID in the combo box, in C# and Visual Studio 2010?
0
 
LVL 7

Assisted Solution

by:rogerard
rogerard earned 500 total points
ID: 34101539
You should not link the combobox directly to the dataset, but rather fill it with the results of a query on a dataset so that it is a static copy that doesn't get impacted by any changes, unless you want them to happen - manually, to the underlying dataset.
0
 
LVL 7

Assisted Solution

by:rogerard
rogerard earned 500 total points
ID: 34102265
An alternative would be to assign the dataset as the datasource of a bindingsource which is the datasource for the datagridview.  Then on the comboboxes Onselectionchanged event, set the bindsource filter to the criteria of the combobox selection.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now