DataSource Property

ListControl.DataSource Property

 

Gets or sets the data source for this ListControl.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member DataSource : Object with get, set

Property Value

Type: System.Object

An object that implements the IList or IListSource interfaces, such as a DataSet or an Array. The default is null.

Exception Condition
ArgumentException

The assigned value does not implement the IList or IListSource interfaces.

There are two ways to fill the ComboBox and ListBox controls.

For example, you can add objects to the ComboBox by using the Add method. You can also add objects to a ComboBox by using the DataSource, DisplayMember, and ValueMember properties to fill the ComboBox.

When the DataSource property is set, a user cannot modify the items collection.

If setting the DataSource property causes the data source to change, the DataSourceChanged event is raised. If setting this property causes the data member to change, the DisplayMemberChanged event is raised.

When you set DataSource to null, DisplayMember is set to an empty string ("").

The following code example is a complete application that shows how you can use DataSource, DisplayMember, ValueMember, and SelectedValue members of the ListControl class as implemented by the ListBox class. The example loads an ArrayList and the list box. When the user selects an item in the list box, the selected value is used to return the data associated with the selected item.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft