BindingSource

Wisej.Web.BindingSource

Namespace: Wisej.Web

Assembly: Wisej.Framework (2.5.0.0)

Encapsulates the data source for a data-bound component.

public class BindingSource : BindingSource, ICurrencyManagerProvider

Constructors

BindingSource()

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

BindingSource(container)

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

Name
Type
Description

BindingSource(dataSource, dataMember)

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

Name
Type
Description

dataSource

The data source for the BindingSource.

dataMember

The specific column or list name within the data source to bind to.

Properties

AllowEdit

Booleanarrow-up-right: Returns whether items in the underlying list can be edited.

AllowNew

Booleanarrow-up-right: Returns or sets whether the AddNew method can be used to add items to the list.

Throws:

AllowRemove

Booleanarrow-up-right: Returns whether the items can be removed from the underlying list.

Count

Int32arrow-up-right: Returns the total number of items in the underlying list, filtered using the current Filter value.

CurrencyManager

CurrencyManager: Returns the currency manager associated with this BindingSource.

Current

Objectarrow-up-right: 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 GetTypearrow-up-right, or ToStringarrow-up-right 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.

DataMember

Stringarrow-up-right: Returns or sets the list in the data source to which the connector currently binds to.

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

DataSource

Objectarrow-up-right: Returns or sets the data source that the connector binds to.

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.

| DataSource | List Result | | :--- | | null | An empty IBindingListarrow-up-right of objects. Adding an item sets the list to the type of the added item. | | null with DataMember set | Not supported, raises ArgumentExceptionarrow-up-right. | | Non-list type or object of type "T" | Empty IBindingListarrow-up-right of type "T". | | Arrayarrow-up-right instance | IBindingListarrow-up-right containing the array elements. | | IEnumerablearrow-up-right instance | An IBindingListarrow-up-right containing the IEnumerablearrow-up-right items. | | List instance containing type "T" | IBindingListarrow-up-right instance containing type "T". |

In addition, DataSource can be set to other list types such as IListSourcearrow-up-right and ITypedListarrow-up-right 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.

Filter

Stringarrow-up-right: Returns or sets the expression used to filter the items in the underlying List.

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 IBindingListViewarrow-up-right 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 DataSetarrow-up-right, DataTablearrow-up-right, or DataViewarrow-up-right, 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.

IsBindingSuspended

Booleanarrow-up-right: Returns whether data binding is suspended.

IsFixedSize

Booleanarrow-up-right: Returns whether the underlying List has a fixed size.

IsReadOnly

Booleanarrow-up-right: Return whether the underlying List is read-only.

IsSorted

Booleanarrow-up-right: Returns whether the items in the underlying List are sorted.

IsSynchronized

Booleanarrow-up-right: Returns whether access to the collection is synchronized (thread safe).

Item(index)

Objectarrow-up-right: Returns or sets the list element at the specified index in the underlying List.

Throws:

List

IListarrow-up-right: Returns the underlying data list.

The BindingSource class uniformly handles different data sources. Ideally the List property should be set to a general IListarrow-up-right. 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 Type | Underlying List Description | | :--- | | DataSource and DataMember are null | An empty ArrayListarrow-up-right. | | DataSource is null, but DataMember is not null | None; an attempt to get the List will throw an ArgumentExceptionarrow-up-right. | | An Arrayarrow-up-right instance | An Arrayarrow-up-right. | | An IListSourcearrow-up-right instance | The return value from a call to the GetList() method of this IListSourcearrow-up-right instance. | | An IBindingListarrow-up-right instance | An IBindingListarrow-up-right. | | An IListarrow-up-right instance | An IListarrow-up-right. | | A non-IListarrow-up-right instance of type "T" | A BindingListarrow-up-right with one element. | | An ICustomTypeDescriptorarrow-up-right instance | An ArrayListarrow-up-right with one element. | | An IEnumerablearrow-up-right | An ArrayListarrow-up-right with the elements copied over. | | The Arrayarrow-up-right type with DataMember of item type "T" | A BindingListarrow-up-right. | | A Type that represents an IListSourcearrow-up-right or ITypedListarrow-up-right | An instance created by a call to the CreateInstance(Type) method of the Activatorarrow-up-right class. A NotSupportedExceptionarrow-up-right may be thrown. | | The IListarrow-up-right type with DataMember of item type "T" or a non-IListarrow-up-right type | A BindingListarrow-up-right | | The ICustomTypeDescriptorarrow-up-right type | None; an attempt to get the List will throw an NotSupportedExceptionarrow-up-right. |

If the type retrieved is the IListarrow-up-right interface, the underlying collection may be more complex, such as an ArrayListarrow-up-right or DataViewarrow-up-right class.

Position

Int32arrow-up-right: Returns or sets the index of the current item in the underlying List.

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.

RaiseListChangedEvents

Booleanarrow-up-right: Returns or sets a value indicating whether ListChanged events should be raised.

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.

RefreshValueOnChange

Booleanarrow-up-right: Enables the automatic refresh of the source property after a data-bound value has been updated in the data source.

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.

Sort

Stringarrow-up-right: Returns or sets the column names used for sorting, and the sort order for viewing the rows in the data source.

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 IBindingListarrow-up-right or IBindingListViewarrow-up-right 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.

SortDescriptions

ListSortDescriptionCollectionarrow-up-right: Returns the collection of sort descriptions applied to the data source.

If the data source is not an IBindingListViewarrow-up-right, the SortDescriptions property always returns null.

SortDirection

ListSortDirectionarrow-up-right: Returns the direction the items in the underlying List are sorted.

If the data source is not an IBindingListarrow-up-right, the SortDirection property always returns Ascendingarrow-up-right.

SortProperty

PropertyDescriptorarrow-up-right: Returns the PropertyDescriptorarrow-up-right that is being used for sorting the underlying List.

If the data source is not an IBindingListarrow-up-right, the SortProperty property always returns null.

SupportsAdvancedSorting

Booleanarrow-up-right: Returns whether the data source supports multi-column sorting.

If the data source is not an IBindingListViewarrow-up-right, the SupportsAdvancedSorting property always returns false.

SupportsChangeNotification

Booleanarrow-up-right: Return whether the data source supports change notification.

SupportsFiltering

Booleanarrow-up-right: Returns whether the data source supports filtering.

If the data source is not an IBindingListarrow-up-right, the SupportsFiltering property always returns false.

SupportsSearching

Booleanarrow-up-right: Returns whether the data source supports searching with the Find method.

If the data source is not an IBindingListarrow-up-right, the SupportsSearching property always returns false.

SupportsSorting

Booleanarrow-up-right: Returns whether the data source supports sorting.

If the data source is not an IBindingListarrow-up-right, the SupportsSorting property always returns false.

SyncRoot

Objectarrow-up-right: Returns an object used to synchronize access to the underlying List.

Methods

Add(item)

Adds an existing item to the underlying List.

Parameter
Type
Description

item

Item to add the underlying List.

Returns: Int32arrow-up-right. The index at which the item was added to the underlying List.

AddNew()

Adds a new item to the underlying List.

Returns: Objectarrow-up-right. The object that was created and added to the underlying List.

ApplySort(property, sort)

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

Parameter
Type
Description

property

A PropertyDescriptorarrow-up-right that describes the property by which to sort the data source.

sort

A ListSortDescriptionarrow-up-right indicating how the list should be sorted.

The IBindingListarrow-up-right implements single column sorting using a PropertyDescriptorarrow-up-right to indicate a property to sort by and a ListSortDirectionarrow-up-right indicating whether the property contents should be sorted in ascending or descending order. Throws:

ApplySort(sorts)

Sorts the data source with the specified sort descriptions.

Parameter
Type
Description

sorts

A ListSortDescriptionCollectionarrow-up-right containing the sort descriptions to apply to the data source.

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

CancelEdit()

Cancels the current edit operation.

Clear()

Removes all elements from the list.

Contains(item)

Determines whether the item is present in he underlying List.

Parameter
Type
Description

item

Item to locate in the underlying List.

Returns: Booleanarrow-up-right. true if the item is found in the List.

CopyTo(array, index)

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

Parameter
Type
Description

array

The destination array.

index

The index in the destination array at which to start the copy.

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 IEditableObjectarrow-up-right interface. If the objects do not implement the IEditableObjectarrow-up-right interface, changes to the data are copied to the underlying data source immediately after each change. This method raises the ListChanged event.

Find(propertyName, value)

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

Parameter
Type
Description

propertyName

The name of the property to search.

value

The value of the item with the specified propertyName to find.

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

Throws:

Find(property, value)

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

Parameter
Type
Description

value

The value of the property to match.

Returns: Int32arrow-up-right. The index of the item that has the given value .

Throws:

GetEnumerator()

Retrieves an enumerator for the underlying List.

Returns: IEnumeratorarrow-up-right. An IEnumeratorarrow-up-right for the List.

GetItemProperties(listAccessors)

Retrieves an array of PropertyDescriptorarrow-up-right objects representing the bindable properties of the data source list type.

Parameter
Type
Description

listAccessors

An array of PropertyDescriptorarrow-up-right objects to find in the List type.

Returns: PropertyDescriptorCollectionarrow-up-right. An array of PropertyDescriptorarrow-up-right objects that represents the properties on this list type used to bind data.

GetListName(listAccessors)

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

Parameter
Type
Description

listAccessors

An array of PropertyDescriptorarrow-up-right objects to find in the list as bindable.

Returns: Stringarrow-up-right. The name of the list supplying the data for binding operations.

GetRelatedCurrencyManager(dataMember)

Returns the related CurrencyManager for the specified data member.

Parameter
Type
Description

dataMember

The 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.

IndexOf(item)

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

Parameter
Type
Description

item

item to locate.

Returns: Int32arrow-up-right. The index of the first occurrence of item in the List.

Insert(index, item)

Inserts an item into the List at the specified index .

Parameter
Type
Description

index

Index at which to insert the item.

item

Item to insert, it can be null.

Throws:

MoveFirst()

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

MoveLast()

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

MoveNext()

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

MovePrevious()

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

Remove(item)

Removes the specified item from the List.

Parameter
Type
Description

item

Item to remove.

RemoveAt(index)

Removes the item at the specified index from the List.

Parameter
Type
Description

index

Index of the item to remove.

RemoveCurrent()

Removes the current item from the List.

RemoveFilter()

Removes the filter associated with this BindingSource

RemoveSort()

Removes the sort information associated with this BindingSource.

Throws:

ResetBindings(metadataChanged)

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

Parameter
Type
Description

metadataChanged

true if the schema has changed; false if only the data has changed.

ResetCurrentItem()

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

ResetItem(itemIndex)

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

Parameter
Type
Description

itemIndex

The index of the item that has changed.

ResumeBinding()

Resumes data binding.

SuspendBinding()

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

Events

AddingNew

AddingNewEventHandlerarrow-up-right Fired before an item is added to the underlying List.

BindingComplete

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

CurrentChanged

EventHandlerarrow-up-right Occurs when the currently bound item changes.

CurrentItemChanged

EventHandlerarrow-up-right Occurs when a property value of the Current property has changed.

DataError

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

DataMemberChanged

EventHandlerarrow-up-right Fired when the DataMember property value has changed.

DataSourceChanged

EventHandlerarrow-up-right Fired when the DataSource property value has changed.

ListChanged

ListChangedEventHandlerarrow-up-right Fired when the underlying List changes or an item in the list changes.

PositionChanged

EventHandlerarrow-up-right Fired after the value of the Position property has changed.

Implements

Name
Description

Provides custom binding management for components.

Last updated

Was this helpful?