Skip to main content
Version: 4.1

BindingExtensions

Namespace: Wisej.Web.Markup

Assembly: Wisej.Framework (4.1.0.0)

Adds fluent markup extension methods to the Control class.

public class BindingExtensions

Methods

Static member Bind<TComponent, TTargetProp, TSource>(component, targetProp, dataSource, sourceProp, formattingEnabled, updateMode, nullValue, formatString, formatProvider, parse, format)

Binds a specified property of a component to a property of a data source.

ParameterTypeDescription
TComponentThe type of the component, which must implement IBindableComponent.
TTargetPropThe type of the target property on the component.
TSourceThe type of the data source.
componentTComponentThe component to bind to.
targetPropExpression<Func<TComponent, TTargetProp>>An expression representing the target property on the component.
dataSourceTSourceThe data source to bind from.
sourcePropStringThe name of the property on the data source to bind to.
formattingEnabled optionalBooleanIndicates whether formatting is enabled. Default is false.
updateMode optionalDataSourceUpdateModeSpecifies when the data source is updated. Default is OnValidation.
nullValue optionalObjectThe value to be used when the data source value is null. Default is null.
formatString optionalStringThe format string to apply. Default is an empty string.
formatProvider optionalIFormatProviderAn object that provides culture-specific formatting information. Default is null.
parse optionalFunc<Object, TTargetProp>A function to convert the data source value to the target property type. Default is null.
format optionalFunc<TTargetProp, Object>A function to convert the target property value to the data source type. Default is null.

Returns: TComponent. The component with the binding applied.

This method allows for complex data binding scenarios where custom parsing and formatting logic is required.


var component = new TextBox();
var dataSource = new { Value = 123 };
component.Bind(c => c.Text, dataSource, "Value", format: v => v.ToString());

Static member Bind<TComponent, TSource>(component, targetProp, dataSource, sourceProp, formattingEnabled, updateMode, nullValue, formatString, formatProvider, parse, format)

Binds a specified property of a component to a data source property with optional formatting and conversion.

ParameterTypeDescription
TComponentThe type of the component implementing IBindableComponent.
TSourceThe type of the data source.
componentTComponentThe component to bind the property to.
targetPropStringThe name of the target property on the component.
dataSourceTSourceThe data source to bind to.
sourcePropStringThe name of the property on the data source to bind to.
formattingEnabled optionalBooleanIndicates whether formatting is enabled. Default is false.
updateMode optionalDataSourceUpdateModeSpecifies when the data source is updated. Default is OnValidation.
nullValue optionalObjectThe value to use when the data source property is null. Default is null.
formatString optionalStringThe format string to apply. Default is an empty string.
formatProvider optionalIFormatProviderThe format provider to use. Default is null.
parse optionalFunc<ConvertEventArgs, Object>A function to convert the data source value to the target property type. Default is null.
format optionalFunc<ConvertEventArgs, Object>A function to convert the target property value to the data source type. Default is null.

Returns: TComponent. The component with the binding applied.

This method is useful for simple data binding scenarios where the target property and data source property types are compatible.


var component = new TextBox();
component.Bind("Text", dataSource, "Name");

Static member Bind<TComponent, TSource>(grid, columnIndex, dataSource, sourceProp, parse, format)

Binds a specified column of the DataGridView to a data source.

ParameterTypeDescription
TComponentThe type of the DataGridView component.
TSourceThe type of the data source.
gridTComponentThe DataGridView to bind.
columnIndexInt32The index of the column to bind.
dataSourceTSourceThe data source to bind to.
sourcePropStringThe property of the data source to bind to the column.
parse optionalFunc<DataGridViewCellParsingEventArgs, Object>Optional. A function to parse cell values. Default is null.
format optionalFunc<DataGridViewCellFormattingEventArgs, Object>Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a column of the DataGridView to a specified property of the data source.


var grid = new DataGridView();
grid.Bind(0, dataSource, "PropertyName");

Static member Bind<TComponent, TSource>(grid, columnIndex, dataSource, dataMember, sourceProp, parse, format)

Binds a specified column of the DataGridView to a data source with a data member.

ParameterTypeDescription
TComponentThe type of the DataGridView component.
TSourceThe type of the data source.
gridTComponentThe DataGridView to bind.
columnIndexInt32The index of the column to bind.
dataSourceTSourceThe data source to bind to.
dataMemberStringThe data member within the data source to bind to.
sourcePropStringThe property of the data source to bind to the column.
parse optionalFunc<DataGridViewCellParsingEventArgs, Object>Optional. A function to parse cell values. Default is null.
format optionalFunc<DataGridViewCellFormattingEventArgs, Object>Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a column of the DataGridView to a specified property of the data source, using a data member.


var grid = new DataGridView();
grid.Bind(0, dataSource, "DataMember", "PropertyName");

Static member Bind<TComponent, TSource>(grid, columnName, dataSource, sourceProp, parse, format)

Binds a specified column of the DataGridView to a data source using the column name.

ParameterTypeDescription
TComponentThe type of the DataGridView component.
TSourceThe type of the data source.
gridTComponentThe DataGridView to bind.
columnNameStringThe name of the column to bind.
dataSourceTSourceThe data source to bind to.
sourcePropStringThe property of the data source to bind to the column.
parse optionalFunc<DataGridViewCellParsingEventArgs, Object>Optional. A function to parse cell values. Default is null.
format optionalFunc<DataGridViewCellFormattingEventArgs, Object>Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a column of the DataGridView to a specified property of the data source using the column name.


var grid = new DataGridView();
grid.Bind("ColumnName", dataSource, "PropertyName");

Static member Bind<TComponent, TSource>(grid, columnName, dataSource, dataMember, sourceProp, parse, format)

Binds a specified column of the DataGridView to a data source with a data member using the column name.

ParameterTypeDescription
TComponentThe type of the DataGridView component.
TSourceThe type of the data source.
gridTComponentThe DataGridView to bind.
columnNameStringThe name of the column to bind.
dataSourceTSourceThe data source to bind to.
dataMemberStringThe data member within the data source to bind to.
sourcePropStringThe property of the data source to bind to the column.
parse optionalFunc<DataGridViewCellParsingEventArgs, Object>Optional. A function to parse cell values. Default is null.
format optionalFunc<DataGridViewCellFormattingEventArgs, Object>Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a column of the DataGridView to a specified property of the data source, using a data member and the column name.


var grid = new DataGridView();
grid.Bind("ColumnName", dataSource, "DataMember", "PropertyName");

Static member Bind<TComponent, TSource>(grid, column, dataSource, sourceProp, parse, format)

Binds a specified DataGridViewColumn to a data source.

ParameterTypeDescription
TComponentThe type of the DataGridView component.
TSourceThe type of the data source.
gridTComponentThe DataGridView to bind.
columnDataGridViewColumnThe DataGridViewColumn to bind.
dataSourceTSourceThe data source to bind to.
sourcePropStringThe property of the data source to bind to the column.
parse optionalFunc<DataGridViewCellParsingEventArgs, Object>Optional. A function to parse cell values. Default is null.
format optionalFunc<DataGridViewCellFormattingEventArgs, Object>Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a DataGridViewColumn to a specified property of the data source.


var grid = new DataGridView();
var column = grid.Columns[0];
grid.Bind(column, dataSource, "PropertyName");

Static member Bind<TComponent, TSource>(grid, column, dataSource, dataMember, sourceProp, parse, format)

Binds a specified DataGridViewColumn to a data source with a data member.

ParameterTypeDescription
TComponentThe type of the DataGridView component.
TSourceThe type of the data source.
gridTComponentThe DataGridView to bind.
columnDataGridViewColumnThe DataGridViewColumn to bind.
dataSourceTSourceThe data source to bind to.
dataMemberStringThe data member within the data source to bind to.
sourcePropStringThe property of the data source to bind to the column.
parse optionalFunc<DataGridViewCellParsingEventArgs, Object>Optional. A function to parse cell values. Default is null.
format optionalFunc<DataGridViewCellFormattingEventArgs, Object>Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a DataGridViewColumn to a specified property of the data source, using a data member.


var grid = new DataGridView();
var column = grid.Columns[0];
grid.Bind(column, dataSource, "DataMember", "PropertyName");

Static member Bind<TComponent, TSource>(listView, columnName, dataSource, sourceProp)

Binds a data source to a specified column in a ListView.

ParameterTypeDescription
TComponentThe type of the ListView component.
TSourceThe type of the data source.
listViewTComponentThe ListView component to bind the data source to.
columnNameStringThe name of the column to bind the data source to.
dataSourceTSourceThe data source to bind.
sourcePropStringThe property of the data source to display in the column.

Returns: TComponent. The ListView component with the data source bound to the specified column.

This method binds a data source to a specified column in a ListView by setting the column's display property name and assigning the data source to the ListView.


var listView = new ListView();
listView.Bind("ColumnName", dataSource, "SourceProperty");

Throws:

  • ArgumentException Thrown when the specified column name does not exist in the ListView.

Static member Bind<TComponent, TSource>(listView, columnName, dataSource, dataMember, sourceProp)

Binds a data source to a specified column in a ListView with a specified data member.

ParameterTypeDescription
TComponentThe type of the ListView component.
TSourceThe type of the data source.
listViewTComponentThe ListView component to bind the data source to.
columnNameStringThe name of the column to bind the data source to.
dataSourceTSourceThe data source to bind.
dataMemberStringThe data member of the data source to bind.
sourcePropStringThe property of the data source to display in the column.

Returns: TComponent. The ListView component with the data source bound to the specified column and data member.

This method binds a data source to a specified column in a ListView by setting the column's display property name, assigning the data member, and then assigning the data source to the ListView.


var listView = new ListView();
listView.Bind("ColumnName", dataSource, "DataMember", "SourceProperty");

Throws:

  • ArgumentException Thrown when the specified column name does not exist in the ListView.

Static member Bind<TComponent, TSource>(listView, column, dataSource, sourceProp)

Binds a data source to a specified column in a ListView.

ParameterTypeDescription
TComponentThe type of the ListView component.
TSourceThe type of the data source.
listViewTComponentThe ListView component to bind the data source to.
columnColumnHeaderThe column to bind the data source to.
dataSourceTSourceThe data source to bind.
sourcePropStringThe property of the data source to display in the column.

Returns: TComponent. The ListView component with the data source bound to the specified column.

This method binds a data source to a specified column in a ListView by setting the column's display property name and assigning the data source to the ListView.


var listView = new ListView();
var column = new ColumnHeader();
listView.Bind(column, dataSource, "SourceProperty");

Throws:

Static member Bind<TComponent, TSource>(listView, column, dataSource, dataMember, sourceProp)

Binds a data source to a specified column in a ListView with a specified data member.

ParameterTypeDescription
TComponentThe type of the ListView component.
TSourceThe type of the data source.
listViewTComponentThe ListView component to bind the data source to.
columnColumnHeaderThe column to bind the data source to.
dataSourceTSourceThe data source to bind.
dataMemberStringThe data member of the data source to bind.
sourcePropStringThe property of the data source to display in the column.

Returns: TComponent. The ListView component with the data source bound to the specified column and data member.

This method binds a data source to a specified column in a ListView by setting the column's display property name, assigning the data member, and then assigning the data source to the ListView.


var listView = new ListView();
var column = new ColumnHeader();
listView.Bind(column, dataSource, "DataMember", "SourceProperty");

Throws: