Solved

Combo box not showing database value

Posted on 2011-03-07
6
248 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Technology Partners: 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!

Question has a verified solution.

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

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

632 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