Solved

Combo box not showing database value

Posted on 2011-03-07
6
245 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
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
System.Security 2 28
Google Directions API to Map URL -C#? 3 37
Problem to refer to value 8 62
Unable to connect C# program to an SQL database - Exception occurs. 4 47
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to implement Singleton Design Pattern in Java.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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