Solved

Load of Combo box does not show selected value

Posted on 2013-01-02
6
292 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.NET Error 7 42
Set form below another form 3 25
Trouble connecting to SqlServer database 4 31
Create XML 5 31
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

19 Experts available now in Live!

Get 1:1 Help Now