Cannot leave focus for databound combobox with lookup table

Posted on 2007-08-11
Last Modified: 2013-12-17
I created a combobox (either by dragging from the database explorer or manually from the toolbox) that is bound to a personnel table with column called employer.  I have a lookup table with the list of employers and their ID #s.  The combobox control is set with the Datasource pointing to the employers binding source, with the data member the employers name and the value member the employers ID.  When this app is run, i set the combobox to the correct employer - however at this time, i can no longer move focus to any other control and I'm forced to quit the application using the stop button on the debugger.  I find its easy enough to set a lookup on a datagridview, but why is it so difficult for a single combo box?

- I can however, leave the box IF i change the contents of the box manually to an integer instead of the drop down text.
Question by:jlrray

    Author Comment

    I broke down and fixed it using the designer.  I dragged the parent table from the data sources window ONTO the bound combobox already on the form. I still don't know why I couldn't do it manually.  But this solution works if you have lookup tables.  If you want to do it manually?  I dont know.

    Author Comment

    Here's my solution to fix it manually.  Say that you have the following table:

    ID (PK)
    Status -- was bound to combobox cboStatus

    You can create a seperate table for the Status if you want.  But in this case, I went with an array cause I wanted it simple.

    I created a class to handle the array.

            private class ComboValString

                private int _id;
                private string _name;

                public ComboValString(int id, string name)
                    this._id = id;
                    this._name = name;

                public int ID { get { return this._id; } }
                public string Name { get { return this._name; } }


    I added the following to the Form_Load event

    private void Form1_Load(object sender, EventArgs e)
                //Load Team Combobox
                ArrayList myArray1 = new ArrayList();

                myArray1.Add(new ComboValString(0, "Admin"));
                myArray1.Add(new ComboValString(1, "Red"));
                myArray1Add(new ComboValString(2, "Blue"));
                myArray1.Add(new ComboValString(3, "White"));

                this.cboStatus.DataSource = arr;
                this.cboStatus.DisplayMember = "Name";
                this.cboStatus.ValueMember = "ID";

    now, if you dragged the combobox from the datasource, you will need to change the
    property of databindings from text to selectedvalue.  That is, move the bound column, which in this case would be 'peoplebindingsource - status' from TEXT to SelectedValue.  Thats it.
    LVL 1

    Accepted Solution

    Closed, 500 points refunded.
    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    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.…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now