Solved

Load of Combo box does not show selected value

Posted on 2013-01-02
6
298 Views
Last Modified: 2013-01-07
I have a combo box on a form.  When I go to open the form and the existing data populates the form, my combo box does not display the value stored in SQL server.  

How can I get my Combo Box to display the value in my record?

I have the datasource, display member, and value member set.
0
Comment
Question by:ndornack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:dustock
ID: 38738082
Please share your code
0
 

Author Comment

by:ndornack
ID: 38738113
public bool addEngOrd;  //indicates if adding to the form or not
        public EngOrd engord; //data from the frmEngOrd (old eng order)
        private EngOrd newEngOrd;  //new data we are capturing here (new eng ord)

        private List<EngOrdType> engOrdTypeList;  //for combobox
        private List<Customer> customerList;  //for combobox
        private string personID; //hold value after combobox selection

        private void frmEngOrdAddModify_Load(object sender, EventArgs e)
        {
            this.LoadComboBoxes();          
            this.LoadDateTimePickers();

            if (addEngOrd)
            {
                this.Text = "Add Engineering Order";
                newEngOrd = new EngOrd();
                engordBindingSource.Clear();
            }
            else
            {
                this.Text = "Modify Engineering Order";
                newEngOrd = new EngOrd();
                this.PutNewEngOrd();
            }
            engordBindingSource.Add(newEngOrd);  //put the existing or a new EngOrd dataset with the binding source

        }

        private void LoadComboBoxes()
        {
            engOrdTypeList = EngOrdTypeDB.GetEngOrdType();
            cboFileType.DataSource = engOrdTypeList;
            cboFileType.SelectedIndex = -1;    
        }
0
 

Author Comment

by:ndornack
ID: 38738114
This happens with "addEngOrd" is false - ie. Modify Engineering Order.
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
LVL 8

Expert Comment

by:JustAndrei
ID: 38738386
Your code loads the list items from EngOrdTypeDB and fills in the control with them, but it does not query which item is currently selected. There no such logic, that's why the list does not show the actual selection.
0
 

Author Comment

by:ndornack
ID: 38738424
Thanks, I will try that.

Why does my other combo box work then?  I don't have code looking for the currently selected record on it and the combo box loads the correct value.  The other combo is called "cboCustomer"
private void LoadComboBoxes()
        {
            engOrdTypeList = EngOrdTypeDB.GetEngOrdType();
            cboFileType.DataSource = engOrdTypeList;
            cboFileType.SelectedIndex = -1;
           
            customerList = CustomerDB.GetCustomerTeamList();
            cboCustomer.DataSource = customerList;
            cboCustomer.SelectedIndex = -1;
        }
0
 
LVL 8

Accepted Solution

by:
JustAndrei earned 500 total points
ID: 38739137
I'm sure cboCustomer is properly initialized somewhere else, because this code (cboCustomer.SelectedIndex = -1;) would only clear the selection, so it's not enough for loading the correct value.
You may look for cboCustomer in other places and find where the selected value or index is set in fact.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

710 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