I bind the combobox cboEmployee like so...
OleDbConnection cn = new
OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
cn.Open();
OleDbDataAdapter da = new OleDbDataAdapter("select employee_number,
employee_name from employees", cn);
DataSet ds = new DataSet();
da.TableMappings.Add("Table", "employees");
da.Fill(ds);
cboEmployees.DataSource = ds.Tables["employees"];
cboEmployees.ValueMember = "employee_number";
cboEmployees.DisplayMember = "employee_name";
cn.Close();
Then I try to get the value (employee_number) from the combobox after it's
been selected (in the click even of a button)...
MessageBox.Show(cboEmployee.SelectedValue.ToString());
However, all I get returned is the employee name, not the employee number.
Any ideas why?
Thanks a lot.
James
>
> However, all I get returned is the employee name, not the employee number.
> Any ideas why?
>
See p. 98 of Karli Watson's book. I just checked and it's in there.
Too complicated to explain here, just buy the book. Combo boxes have
a property that binds them to the .XSD schematic. I also assume you
know about how list boxes/combo boxes can display a different value
than what is bound, but that's another issue.
RL
Beginning C# 2005 Databases (Programmer to Programmer) by Karli Watson
(Paperback - Oct. 16, 2006)
You can also do a Google (or, your favorite search engine) search for:
"Beginning C# 2005 Databases (Programmer to Programmer) by Karli Watson"
and discover places to download sample chapters, etc.