Solved

Load of Combo box does not show selected value

Posted on 2013-01-02
6
294 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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:…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

810 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