?
Solved

Cannot leave focus for databound combobox with lookup table

Posted on 2007-08-11
4
Medium Priority
?
217 Views
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.
0
Comment
Question by:jlrray
  • 2
3 Comments
 

Author Comment

by:jlrray
ID: 19676496
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.
0
 

Author Comment

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

People
------------
ID (PK)
Name
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.
0
 
LVL 1

Accepted Solution

by:
Vee_Mod earned 0 total points
ID: 19722242
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

864 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