Skip to main content
Version: 4.1

BindingSource

Namespace: Wisej.Web

Assembly: Wisej.Framework (4.1.0.0)

Encapsulates the data source for a data-bound component.

public class BindingSource : BindingSource, ICurrencyManagerProvider

Constructors

Instance member BindingSource()

Initializes a new instance of the BindingSource class to the default property values.

Instance member BindingSource(container)

Initializes a new instance of the BindingSource class and adds the BindingSource to the specified container.

NameTypeDescription
containerIContainerThe IContainer to add the current BindingSource to.

Instance member BindingSource(dataSource, dataMember)

Initializes a new instance of the BindingSource class with the specified data source and data member.

NameTypeDescription
dataSourceObjectThe data source for the BindingSource.
dataMemberStringThe specific column or list name within the data source to bind to.

Instance member BindingSource(dataSource)

Initializes a new instance of the BindingSource class with the specified data source.

NameTypeDescription
dataSourceObjectThe data source for the BindingSource.

Properties

Instance member AllowEdit

Boolean: Returns whether items in the underlying list can be edited.

Instance member AllowNew

Boolean: Returns or sets whether the AddNew method can be used to add items to the list.

Throws:

  • InvalidOperationException This property is set to true when the underlying list represented by the List property has a fixed size or is read-only.
  • MissingMethodException The property is set to true and the AddingNew event is not handled when the underlying list type does not have a default constructor.

Instance member AllowRemove

Boolean: Returns whether the items can be removed from the underlying list.

Instance member Count

Int32: Returns the total number of items in the underlying list, filtered using the current Filter value.

Instance member CurrencyManager

CurrencyManager: Returns the currency manager associated with this BindingSource.

Instance member Current

Object: Returns the current item in the list.

Use the Current property to access the current item, but use the List property to get the entire list. To determine the type of the current object, use the GetType, or ToString methods.

To change the current item, set the Position property to a new integral value, or use one of the navigation methods such as MoveNext.

Instance member DataMember

String: Returns or sets the list in the data source to which the connector currently binds to. (Default: "")

If the DataSource contains multiple lists (or tables) of data, you should set the DataMember property to the name of one of the sources.

Setting this property raises the DataMemberChanged event

Instance member DataSource

Object: Returns or sets the data source that the connector binds to. (Default: null)

The DataSource property can be set to a number of data sources, including types, objects, and lists of types. The resulting data source will be exposed as a list. The following table shows some of the common data sources and the resulting list evaluation.

DataSourceList Result
nullAn empty
null withNot supported, raises
Non-list type or object of type "T"Empty
ArrayIBindingList
IEnumerableAn
List instance containing type "T"IBindingList

In addition, DataSource can be set to other list types such as IListSource and ITypedList and the BindingSource will handle them appropriately. In this case, the type contained in the list should have a parameterless constructor.

When setting a data source, if the supplied reference contains more than one list or table, you must set the DataMember property to a string that specifies the list to bind to. Setting this property raises the DataSourceChanged event.

Instance member Filter

String: Returns or sets the expression used to filter the items in the underlying List. (Default: null)

Typically used in complex data-binding scenarios, the Filter property allows you to view a subset of the DataSource. Only underlying lists that implement the IBindingListView interface support filtering.

When Filter is not null, the BindingSource passes this property to the underlying list. If you set this property during object initialization, the call will be deferred until after initialization is complete.

To form a filter value, specify the name of a column followed by an operator and a value to filter on. The accepted filter syntax depends on the underlying data source. If the underlying data source is a DataSet, DataTable, or DataView, you can specify Boolean expressions using the syntax documented for the DataColumn.Expression property.

The value of the Filter property affects the value of the Count property. Additionally, the Filter value will persist when the data source changes. To stop filtering the DataSource, call the RemoveFilter method.

Instance member IsBindingSuspended

Boolean: Returns whether data binding is suspended.

Instance member IsFixedSize

Boolean: Returns whether the underlying List has a fixed size.

Instance member IsReadOnly

Boolean: Return whether the underlying List is read-only.

Instance member IsSorted

Boolean: Returns whether the items in the underlying List are sorted.

Instance member IsSynchronized

Boolean: Returns whether access to the collection is synchronized (thread safe).

Instance member Item(index)

Object: Returns or sets the list element at the specified index in the underlying List.

Throws:

Instance member List

IList: Returns the underlying data list.

The BindingSource class uniformly handles different data sources. Ideally the List property should be set to a general IList. However, sometimes it may be necessary to cast this property to a more specific type. The following table shows the underlying list type, which depends on the type or value of the data source.

DataSource TypeUnderlying List Description
DataSourceAn empty
DataSourceNone; an attempt to get the List will throw an
AnAn
AnThe return value from a call to the GetList() method of this
AnAn
AnAn
A non-A
AnAn
AnAn
TheA
A Type that represents anAn instance created by a call to the CreateInstance(Type) method of the
TheA
TheNone; an attempt to get the

If the type retrieved is the IList interface, the underlying collection may be more complex, such as an ArrayList or DataView class.

Instance member Position

Int32: Returns or sets the index of the current item in the underlying List. (Default: -1)

When setting the Position property, out-of-range values are treated in the following manner:

  • Negative values are treated as 0.
  • Values greater than or equal to Count are treated as Count minus 1.

Changing the Position property will adjust the Current property.

Instance member RaiseListChangedEvents

Boolean: Returns or sets a value indicating whether ListChanged events should be raised. (Default: True)

When the RaiseListChangedEvents property is false, it suspends the raising of the ListChanged events. This event indicates that the bound list has been modified in some way, including adding, deleting, inserting, or modifying items.

Instance member RefreshValueOnChange

Boolean: Enables the automatic refresh of the source property after a data-bound value has been updated in the data source. (Default: False)

This option fixes a long standing "feature" of the default BindingSource where the property that is the source of a value change is not refreshed automatically after it updates the bound data source. In a scenario where the data source "transforms" the value received from a data-bound control, the source property is not updated while all other bound properties are.

Instance member Sort

String: Returns or sets the column names used for sorting, and the sort order for viewing the rows in the data source. (Default: null)

The Sort property is a case-sensitive string that specifies the column names used to sort the rows, along with the SortDirection. Columns are sorted ascending by default. Multiple columns can be separated by commas, such as "State, ZipCode DESC".

To support sorting, the underlying List must implement the IBindingList or IBindingListView interfaces. This capability can be queried through the SupportsSorting property. Multicolumn sorting is available when the SupportsAdvancedSorting property is true.

Setting the Sort property will change the internal list depending on its type:

The internal list's sort properties are only changed when the sort string is not null. The get accessor for this property will not retrieve the sort value of the internal list; instead, it will return the set accessor value. The value of the Sort property will persist when the data source changes.

Instance member SortDescriptions

ListSortDescriptionCollection: Returns the collection of sort descriptions applied to the data source.

If the data source is not an IBindingListView, the SortDescriptions property always returns null.

Instance member SortDirection

ListSortDirection: Returns the direction the items in the underlying List are sorted.

If the data source is not an IBindingList, the SortDirection property always returns Ascending.

Instance member SortProperty

PropertyDescriptor: Returns the PropertyDescriptor that is being used for sorting the underlying List.

If the data source is not an IBindingList, the SortProperty property always returns null.

Instance member SupportsAdvancedSorting

Boolean: Returns whether the data source supports multi-column sorting.

If the data source is not an IBindingListView, the SupportsAdvancedSorting property always returns false.

Instance member SupportsChangeNotification

Boolean: Return whether the data source supports change notification.

Instance member SupportsFiltering

Boolean: Returns whether the data source supports filtering.

If the data source is not an IBindingList, the SupportsFiltering property always returns false.

Instance member SupportsSearching

Boolean: Returns whether the data source supports searching with the Find method.

If the data source is not an IBindingList, the SupportsSearching property always returns false.

Instance member SupportsSorting

Boolean: Returns whether the data source supports sorting.

If the data source is not an IBindingList, the SupportsSorting property always returns false.

Instance member SyncRoot

Object: Returns an object used to synchronize access to the underlying List.

Methods

Instance member Add(item)

Adds an existing item to the underlying List.

ParameterTypeDescription
itemObjectItem to add the underlying List.

Returns: Int32. The index at which the item was added to the underlying List.

Instance member AddNew()

Adds a new item to the underlying List.

Returns: Object. The object that was created and added to the underlying List.

Instance member ApplySort(property, sort)

Sorts the data source using the specified property descriptor and sort direction.

ParameterTypeDescription
propertyPropertyDescriptorA PropertyDescriptor that describes the property by which to sort the data source.
sortListSortDirectionA ListSortDescription indicating how the list should be sorted.

The IBindingList implements single column sorting using a PropertyDescriptor to indicate a property to sort by and a ListSortDirection indicating whether the property contents should be sorted in ascending or descending order. Throws:

Instance member ApplySort(sorts)

Sorts the data source with the specified sort descriptions.

ParameterTypeDescription
sortsListSortDescriptionCollectionA ListSortDescriptionCollection containing the sort descriptions to apply to the data source.

IBindingListView implements multi-column sorting as a set of property descriptor-direction pairs. Throws:

Instance member CancelEdit()

Cancels the current edit operation.

Instance member Clear()

Removes all elements from the list.

Instance member Contains(item)

Determines whether the item is present in he underlying List.

ParameterTypeDescription
itemObjectItem to locate in the underlying List.

Returns: Boolean. true if the item is found in the List.

Instance member CopyTo(array, index)

Copies the contents of the List to the specified array , starting at the specified index value.

ParameterTypeDescription
arrayArrayThe destination array.
indexInt32The index in the destination array at which to start the copy.

Instance member EndEdit()

Applies pending changes to the underlying data source.

When the EndEdit method is called, all pending changes are applied to the underlying data source.

This method has no effect unless the objects contained by the data source implement the IEditableObject interface. If the objects do not implement the IEditableObject interface, changes to the data are copied to the underlying data source immediately after each change.

This method raises the ListChanged event.

Instance member Find(propertyName, value)

Returns the index of the item in the list with the specified propertyName and value .

ParameterTypeDescription
propertyNameStringThe name of the property to search.
valueObjectThe value of the item with the specified propertyName to find.

Returns: Int32. The zero-based index of the item with the specified propertyName and value .

Throws:

Instance member Find(property, value)

Searches for the index of the that has the given value in the specified property .

ParameterTypeDescription
propertyPropertyDescriptorThe PropertyDescriptor to search.
valueObjectThe value of the property to match.

Returns: Int32. The index of the item that has the given value .

Throws:

Instance member GetCommandProperties()

Retrieves the collection of PropertyDescriptor objects representing the bindable ICommand properties defined on the DataSource object.

Returns: PropertyDescriptorCollection. An collection of PropertyDescriptor objects that represents the commands on the data source.

Instance member GetEnumerator()

Retrieves an enumerator for the underlying List.

Returns: IEnumerator. An IEnumerator for the List.

Instance member GetItemProperties(listAccessors)

Retrieves an collection of PropertyDescriptor objects representing the bindable properties of the data source list type.

ParameterTypeDescription
listAccessorsPropertyDescriptor[]An array of PropertyDescriptor objects to find in the List type.

Returns: PropertyDescriptorCollection. An collection of PropertyDescriptor objects that represents the properties on this list type used to bind data.

Instance member GetListName(listAccessors)

Returns the name of the list supplying data for the binding operations.

ParameterTypeDescription
listAccessorsPropertyDescriptor[]An array of PropertyDescriptor objects to find in the list as bindable.

Returns: String. The name of the list supplying the data for binding operations.

Instance member GetRelatedCurrencyManager(dataMember)

Returns the related CurrencyManager for the specified data member.

ParameterTypeDescription
dataMemberStringThe name of column or list, within the data source to retrieve the currency manager for.

Returns: CurrencyManager. The related CurrencyManager for the specified data member.

Instance member IndexOf(item)

Returns the index of the specified item in the underlying List.

ParameterTypeDescription
itemObjectitem to locate.

Returns: Int32. The index of the first occurrence of item in the List.

Instance member Insert(index, item)

Inserts an item into the List at the specified index .

ParameterTypeDescription
indexInt32Index at which to insert the item.
itemObjectItem to insert, it can be null.

Throws:

Instance member MoveFirst()

Moves the current position to the first item in the List.

Instance member MoveLast()

Moves the current position to the last item in the List.

Instance member MoveNext()

Moves the current position to the next item in the List.

Instance member MovePrevious()

Moves the current position to the previous item in the List.

Protected member OnAddingNew(e)

Fires the AddingNew event.

ParameterTypeDescription
eAddingNewEventArgsA AddingNewEventArgs that contains the event data.

Protected member OnBindingComplete(e)

Fires the BindingComplete event.

ParameterTypeDescription
eBindingCompleteEventArgsA BindingCompleteEventArgs that contains the event data.

Protected member OnCurrentChanged(e)

Fires the CurrentChanged event.

ParameterTypeDescription
eEventArgsAn EventArgs that contains the event data.

Protected member OnCurrentItemChanged(e)

Fires the CurrentItemChanged event.

ParameterTypeDescription
eEventArgsAn EventArgs that contains the event data.

Protected member OnDataError(e)

Fires the DataError event.

ParameterTypeDescription
eBindingManagerDataErrorEventArgsA BindingManagerDataErrorEventArgs that contains the event data.

Protected member OnDataMemberChanged(e)

Fires the DataMemberChanged event.

ParameterTypeDescription
eEventArgsAn EventArgs that contains the event data.

Protected member OnDataSourceChanged(e)

Fires the DataSourceChanged event.

ParameterTypeDescription
eEventArgsAn EventArgs that contains the event data.

Protected member OnListChanged(e)

Fires the ListChanged event.

ParameterTypeDescription
eListChangedEventArgsA ListChangedEventArgs that contains the event data.

Protected member OnPositionChanged(e)

Fires the PositionChanged event.

ParameterTypeDescription
eEventArgsAn EventArgs that contains the event data.

Instance member Remove(item)

Removes the specified item from the List.

ParameterTypeDescription
itemObjectItem to remove.

Instance member RemoveAt(index)

Removes the item at the specified index from the List.

ParameterTypeDescription
indexInt32Index of the item to remove.

Instance member RemoveCurrent()

Removes the current item from the List.

Instance member RemoveFilter()

Removes the filter associated with this BindingSource

Instance member RemoveSort()

Removes the sort information associated with this BindingSource.

Throws:

Instance member ResetBindings()

Causes a control bound to this BindingSource to re-read all the items and refresh their displayed value.

Instance member ResetBindings(metadataChanged)

Causes a control bound to this BindingSource to re-read all the items and refresh their displayed value.

ParameterTypeDescription
metadataChangedBooleantrue if the schema has changed; false if only the data has changed.

Instance member ResetCurrentItem()

Causes a control bound to this BindingSource to re-read the current item and refresh the displayed value.

Instance member ResetItem(itemIndex)

Causes a control bound to this BindingSource to read the item at the specified itemIndex and refresh the displayed value.

ParameterTypeDescription
itemIndexInt32The index of the item that has changed.

Instance member ResumeBinding()

Resumes data binding.

Instance member SuspendBinding()

Suspends data binding to prevent changes from updating the data-bound data source.

Events

Instance member AddingNew

AddingNewEventHandler Fired before an item is added to the underlying List.

Instance member BindingComplete

BindingCompleteEventHandler Fired when all the clients have been bound to this BindingSource.

Instance member CurrentChanged

EventHandler Occurs when the currently bound item changes.

Instance member CurrentItemChanged

EventHandler Occurs when a property value of the Current property has changed.

Instance member DataError

BindingManagerDataErrorEventHandler Fired when a currency-related exception is silently handled by the BindingSource.

Instance member DataMemberChanged

EventHandler Fired when the DataMember property value has changed.

Instance member DataSourceChanged

EventHandler Fired when the DataSource property value has changed.

Instance member ListChanged

ListChangedEventHandler Fired when the underlying List changes or an item in the list changes.

Instance member PositionChanged

EventHandler Fired after the value of the Position property has changed.

Implements

NameDescription
ICurrencyManagerProviderProvides custom binding management for components.