• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

Combo-box crashing Win-forms C# app

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
Adapt2NL
Asked:
Adapt2NL
  • 4
  • 2
3 Solutions
 
rogerardCommented:
in the form's onclose event, try setting the combobox datasource to no nothing
0
 
Adapt2NLAuthor Commented:
Do you have any idea why the SelectedIndexChanged keeps reoccurring?
0
 
rogerardCommented:
Sorry, no.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
Adapt2NLAuthor Commented:
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
 
rogerardCommented:
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
 
rogerardCommented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now