Data Binding in Windows Forms MultiSelectionComboBox
27 Apr 2021 / 1 minute to read
MultiSelectionComboBox control can be bound with external data source. Objects that can acts as Datasource to MultiSelectionComboBox are
You can add objects to the MultiSelectionComboBox by using the Items method. You can also add objects to a MultiSelectionComboBox using the DataSource, DisplayMember and ValueMember properties to fill the ComboBox. When the DataSource property is set, you cannot modify the items collection. When the DataSource property setting causes the data source to change, the DataSourceChanged event is raised .When you set DataSource to a null, DisplayMember is set with an empty string (“”).
|DataSource||Indicates the list that this control will use to get its items.|
|DisplayMember||Indicates the property to display for the items in this control.|
|ValueMember||Indicates the property to use as the actual value for the items in the control.|
//Specifies the DataSource to MultiSelectionComboBox. this.multiSelectionComboBox1.DataSource = dataTable; //To set Display Member for the MultiSelectionComboBox. this.multiSelectionComboBox1.DisplayMember = "Name"; //To set value member for the MultiSelectionComboBox. this.multiSelectionComboBox1.ValueMember = "ID";
'Specifies the DataSource to MultiSelectionComboBox. Me.multiSelectionComboBox1.DataSource = dataTable 'To set Display Member for the MultiSelectionComboBox. Me.multiSelectionComboBox1.DisplayMember = "Name" 'To set value member for the MultiSelectionComboBox. Me.multiSelectionComboBox1.ValueMember = "ID"