Gold
Gold

Reputation: 62424

How to Bind List<> to ComboBox?

I have this code :

    public static List<string> MyTable = new List<string>();

dsView = new DataSet();

adp = new SqlCeDataAdapter("SELECT DISTINCT Fname FROM MEN", Conn);

adp.Fill(dsView, "MEN");

adp.Dispose();

foreach (DataRow R in dsView.Tables["MEN"].Rows)

GG.Add( R["Fname"].ToString());

how to Bind it to ComboBox ?

thank's in advance

Upvotes: 0

Views: 742

Answers (1)

JDunkerley
JDunkerley

Reputation: 12495

You just set the ComboBox's DataSource equal to the List.

comboBox1.DataSource = MyTable;

If you use a System.ComponentModel.BindingList instead of a List then changes to the list will be sent to the ComboBox

Also should your last line:

GG.Add( R["Fname"].ToString());

be

MyTable.Add( R["Fname"].ToString());

Upvotes: 4

Related Questions