ComboForm1 Datasource Question

S

Sammut

Hi,

I am creating a comboform and trying to show a field from an access tables
but I cannot get how to tell the comboform what field from the table I want
to see

The access database is called "ecs"
The table I want is called "locality" and has 2 fields "Code" & "Text" nwo I
want to show the field text in my combo. This is my code so far but all I
get in my combo is a list of "System.Data.DataRowView".

OleDbConnection conn1 = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=d:\\cecs\\ecs.mdb");

conn1.Open();

//

System.Data.DataSet ds = new DataSet();

OleDbDataAdapter daLocality = new OleDbDataAdapter("select desc from
locality",conn1);

daLocality.Fill(ds,"Locality");

comboBox1.DataSource = ds.Tables["Locality"];





Any idea how to set what field I want to show.

Thanks

Ivan Sammut
 
W

William Ryan eMVP

Add this

comboBox1.DisplayMember = "Text";
comboBox1.ValueMember = "Code";
then SelectedItem ToString will be the value in the textBox, but
SelectedValue will be the value in Code that corresponds the the value in
Text
ALso, I'd change the field name of text in that it's a property name and if
you add databindings, the first argument is the property you are binding to,
which is often "Text" . I think it might give you some grief.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top