Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Combo box not showing database value

Posted on 2011-03-07
6
Medium Priority
?
249 Views
Last Modified: 2012-05-11
I created a combo box that will display an employee name but store the Employee NO.  The code will create the drop down properly, and when I step thru the code, it is obtaining the correct EmployeeNO to update, but it only displays the first employee name in the list.  I'm sure this is a simple problem, but I don't see what I have done wrong.

on Load:
LoadEmployees();
 LoadPatient();

  private void LoadEmployees()
        {
            m_EmployeeNames = new EmployeeSUID();
            try
            {
                m_EmployeeNames.GetEmployees();
                m_dtEmployee = m_EmployeeNames.GetEmployee;
                // Setup the combobox view and display-, value member
                cbxPreferredCaller.DataSource = m_dtEmployee;
                cbxPreferredCaller.DisplayMember = "FullName";
                cbxPreferredCaller.ValueMember = "EmployeeNO";
                cbxPreferredCaller.DataBindings.Add("SelectedValue", m_dtEmployee, "EmployeeNO");
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                   
            }

 private void LoadPatient()
        {
            int index=0;

            try
            {
                m_patientData = m_mdiParentForm.PatientSUID;
     
                //Set PrimaryCaller comboBox
                m_EmployeeNames.GetEmployeebyEmplNo(m_patientData.PatientRcd.PrimaryCaller);
               
                cbxPreferredCaller.GetItemText(m_patientData.PatientRcd.PrimaryCaller);
               

                tbxMRN.Text = m_patientData.PatientRcd.MRN.ToString();
             
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

I hope this is enough to see what I have done wrong.
Thanks
0
Comment
Question by:LenTompkins
[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
6 Comments
 
LVL 9

Expert Comment

by:gery128
ID: 35065988
Replace this line :
cbxPreferredCaller.DataBindings.Add("SelectedValue", m_dtEmployee, "EmployeeNO");

with this:
cbxPreferredCaller.DataBind();

It should work.
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 35066198
Hi, For getting value from combobox you have to first bind their values as a ValueMember and DataMember.
0
 
LVL 1

Expert Comment

by:lalitgada
ID: 35067624
check only the datasource and datamember
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:LenTompkins
ID: 35068533
qery128, DataBind is used for web applications and this is a windows application.  
Samirbhoqayta, how do you bind their values as a value member and datamember?  Can you give an example.
0
 

Accepted Solution

by:
LenTompkins earned 0 total points
ID: 35072369
I ended up solving the problem .  Here is what I had to do for a windows application:

 private DataTable m_dtEmployee;
 private BindingSource m_bndEmployee;


OnLoad
 LoadEmployees();
  LoadPatient();

 private void LoadEmployees()
        {
            m_EmployeeNames = new EmployeeSUID();
            this.m_bndEmployee = new BindingSource();
           
            try
            {
                // obtain all employees and store in data table
                m_EmployeeNames.GetEmployees();
                m_dtEmployee = m_EmployeeNames.GetEmployee;
                // set binding source data source to data table
                this.m_bndEmployee.DataSource = m_dtEmployee;
                // set binding source to the data source of combo box
                cbxPreferredCaller.DataSource = m_bndEmployee;
                // Setup the combobox view and display-, value member
                cbxPreferredCaller.DisplayMember = "FullName";
                cbxPreferredCaller.ValueMember = "EmployeeNO";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                   
            }

 LoadPatient()
{
              //Set PrimaryCaller comboBox
                m_EmployeeNames.GetEmployeebyEmplNo(m_patientData.PatientRcd.PrimaryCaller);
                cbxPreferredCaller.Text = m_EmployeeNames.EmployeeName;
}
0
 

Author Closing Comment

by:LenTompkins
ID: 35120677
I finally figured out how to solve the problem
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This video teaches viewers about errors in exception handling.

688 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