Solved

Load of Combo box does not show selected value

Posted on 2013-01-02
6
293 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c# string handling 1 27
C# Json POSt to Rest API 4 35
Variable Event ? 3 22
Write to file when application closes (by logoff) - VB.NET 1 20
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:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

20 Experts available now in Live!

Get 1:1 Help Now