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
Solved

Load of Combo box does not show selected value

Posted on 2013-01-02
6
295 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 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