Skip to main content
Version: 3.5

BindingSource

Namespace: Wisej.Web

Assembly: Wisej.Framework (3.5.0.0)

Encapsulates the data source for a data-bound component.

public class BindingSource : BindingSource, ICurrencyManagerProvider

Constructors

Instance memberBindingSource()

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

Instance memberBindingSource(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 memberBindingSource(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 memberBindingSource(dataSource)

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

NameTypeDescription
dataSourceObjectThe data source for the BindingSource.

Properties

Instance memberAllowEdit

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

Instance memberAllowNew

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 memberAllowRemove

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

Instance memberCount

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

Instance memberCurrencyManager

CurrencyManager: Returns the currency manager associated with this BindingSource.

Instance memberCurrent

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 memberDataMember

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 memberDataSource

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 memberFilter

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 memberIsBindingSuspended

Boolean: Returns whether data binding is suspended.

Instance memberIsFixedSize

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

Instance memberIsReadOnly

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

Instance memberIsSorted

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

Instance memberIsSynchronized

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

Instance memberItem(index)

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

Throws:

Instance memberList

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 memberPosition

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 memberRaiseListChangedEvents

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 memberRefreshValueOnChange

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 memberSort

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 memberSortDescriptions

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 memberSortDirection

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 memberSortProperty

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 memberSupportsAdvancedSorting

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 memberSupportsChangeNotification

Boolean: Return whether the data source supports change notification.

Instance memberSupportsFiltering

Boolean: Returns whether the data source supports filtering.

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

Instance memberSupportsSearching

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 memberSupportsSorting

Boolean: Returns whether the data source supports sorting.

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

Instance memberSyncRoot

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

Methods

Instance memberAdd(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 memberAddNew()

Adds a new item to the underlying List.

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

Instance memberApplySort(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 memberApplySort(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 memberCancelEdit()

Cancels the current edit operation.

Instance memberClear()

Removes all elements from the list.

Instance memberContains(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 memberCopyTo(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 memberEndEdit()

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 memberFind(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 memberFind(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 memberGetCommandProperties()

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 memberGetEnumerator()

Retrieves an enumerator for the underlying List.

Returns: IEnumerator. An IEnumerator for the List.

Instance memberGetItemProperties(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 memberGetListName(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 memberGetRelatedCurrencyManager(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 memberIndexOf(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 memberInsert(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 memberMoveFirst()

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

Instance memberMoveLast()

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

Instance memberMoveNext()

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

Instance memberMovePrevious()

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

Instance memberRemove(item)

Removes the specified item from the List.

ParameterTypeDescription
itemObjectItem to remove.

Instance memberRemoveAt(index)

Removes the item at the specified index from the List.

ParameterTypeDescription
indexInt32Index of the item to remove.

Instance memberRemoveCurrent()

Removes the current item from the List.

Instance memberRemoveFilter()

Removes the filter associated with this BindingSource

Instance memberRemoveSort()

Removes the sort information associated with this BindingSource.

Throws:

Instance memberResetBindings()

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

Instance memberResetBindings(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 memberResetCurrentItem()

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

Instance memberResetItem(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 memberResumeBinding()

Resumes data binding.

Instance memberSuspendBinding()

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

Events

Instance memberAddingNew

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

Instance memberBindingComplete

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

Instance memberCurrentChanged

EventHandler Occurs when the currently bound item changes.

Instance memberCurrentItemChanged

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

Instance memberDataError

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

Instance memberDataMemberChanged

EventHandler Fired when the DataMember property value has changed.

Instance memberDataSourceChanged

EventHandler Fired when the DataSource property value has changed.

Instance memberListChanged

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

Instance memberPositionChanged

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

Implements

NameDescription
ICurrencyManagerProviderProvides custom binding management for components.