Solved

Combo box not showing database value

Posted on 2011-03-07
6
242 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
6 Comments
 
LVL 9

Expert Comment

by:gery128
Comment Utility
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
Comment Utility
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
Comment Utility
check only the datasource and datamember
0
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.

 

Author Comment

by:LenTompkins
Comment Utility
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
Comment Utility
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
Comment Utility
I finally figured out how to solve the problem
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

762 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

6 Experts available now in Live!

Get 1:1 Help Now