0

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

H H
  • 263,252
  • 30
  • 330
  • 514
Gold
  • 60,526
  • 100
  • 215
  • 315
  • 3
    What are you developing? Windows app using WinForms? Web app using Webforms or MVC? WPF app? Silverlight app? Mobile app? – Joseph Oct 07 '09 at 15:31

1 Answers1

4

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());
JDunkerley
  • 12,355
  • 5
  • 41
  • 45