ComboBox control data binding method
The ComboBox control has different attributes in Silverlight3 and Silverlight4 and is used in Silverlight4.
Bind a ComboBox control or ListBox control
Set the DataSource property to a data source object. Possible data sources include data tables, data views, datasets, data view managers, arrays, or any class that implements the IList interface. For more information, see the Windows Forms data provider.
Set the DisplayMember attribute to the name of a column in the data source object:
Copy 'visual Basic
Private Sub BindComboBox ()
ComboBox1.DataSource = DataSet1.Tables ("Suppliers ")
ComboBox1.DisplayMember = "ProductName"
End Sub
// C #
Private void BindComboBox ()
{
ComboBox1.DataSource = dataSet1.Tables ["Suppliers"];
ComboBox1.DisplayMember = "ProductName ";
}
NOTE: If it is bound to a data source that does not implement the IBindingList interface (such as the ArrayList object), the data of the bound control will not be updated when updating the data source. For example, if you bind a combo box to an ArrayList object and add data to the ArrayList, these new items will not appear in the combo box. However, you can force update the combo box by calling the SuspendBinding and ResumeBinding methods of the BindingContext class bound to the control.
See the instance below
<ComboBox x: Name = "ComboNewsSortName" Style = "{StaticResource ComboBoxStyle1}" ItemsSource = "{Binding}" DisplayMemberPath = "NewsSortName" SelectedValuePath = "NewsSortID">
</ComboBox>
Cs:
ComboNewsSortName. DataContext = e. Result; // data source binding
Int inewsSortID = Convert. ToInt32 (newsInfoRow ["NewsSortIDParamerter"]);
ComboNewsSortName. SelectedValue = inewsSortID; // Value
NewsDomain newsInfo = new NewsDomain ();
NewsInfo. NewsSortID = Convert. ToInt32 (ComboNewsSortName. SelectedValue); // assign a value