Monday, 5 December 2011

How to: Bind a ComboBox or ListBox Control to Data

  1. Set the DataSource property to a data source object.
    Possible data sources include a BindingSource bound to data,
    a data table,
    an array,
    a data view,
    a dataset,
    a data view manager,
    or any class that implements the IList interface.
  2. If you are binding to a table,
    set the DisplayMember property to the name of a column in the data source.
    - or -
    If you are binding to an List,
    set the display member to a public property of the type in the list.


     
    private void BindComboBox()
    {
      comboBox1.DataSource = dataSet1.Tables["Suppliers"];
      comboBox1.DisplayMember = "ProductName";
    } 
     
     
    Private Sub BindComboBox()
      ComboBox1.DataSource = DataSet1.Tables("Suppliers")
      ComboBox1.DisplayMember = "ProductName"
    End Sub
    
    

0 comments:

Post a Comment