BindingExtensions
Namespace: Wisej.Web.Markup
Assembly: Wisej.Framework (4.1.0.0)
Adds fluent markup extension methods to the Control class.
- C#
- VB.NET
public class BindingExtensions
Public Class BindingExtensions
Methods
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.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the component, which must implement IBindableComponent. | |
| TTargetProp | The type of the target property on the component. | |
| TSource | The type of the data source. | |
| component | TComponent | The component to bind to. |
| targetProp | Expression<Func<TComponent, TTargetProp>> | An expression representing the target property on the component. |
| dataSource | TSource | The data source to bind from. |
| sourceProp | String | The name of the property on the data source to bind to. |
| formattingEnabled | Boolean | Indicates whether formatting is enabled. Default is false. |
| updateMode | DataSourceUpdateMode | Specifies when the data source is updated. Default is OnValidation. |
| nullValue | Object | The value to be used when the data source value is null. Default is null. |
| formatString | String | The format string to apply. Default is an empty string. |
| formatProvider | IFormatProvider | An object that provides culture-specific formatting information. Default is null. |
| parse | Func<Object, TTargetProp> | A function to convert the data source value to the target property type. Default is null. |
| format | Func<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());
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.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the component implementing IBindableComponent. | |
| TSource | The type of the data source. | |
| component | TComponent | The component to bind the property to. |
| targetProp | String | The name of the target property on the component. |
| dataSource | TSource | The data source to bind to. |
| sourceProp | String | The name of the property on the data source to bind to. |
| formattingEnabled | Boolean | Indicates whether formatting is enabled. Default is false. |
| updateMode | DataSourceUpdateMode | Specifies when the data source is updated. Default is OnValidation. |
| nullValue | Object | The value to use when the data source property is null. Default is null. |
| formatString | String | The format string to apply. Default is an empty string. |
| formatProvider | IFormatProvider | The format provider to use. Default is null. |
| parse | Func<ConvertEventArgs, Object> | A function to convert the data source value to the target property type. Default is null. |
| format | Func<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");
Bind<TComponent, TSource>(grid, columnIndex, dataSource, sourceProp, parse, format)
Binds a specified column of the DataGridView to a data source.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the DataGridView component. | |
| TSource | The type of the data source. | |
| grid | TComponent | The DataGridView to bind. |
| columnIndex | Int32 | The index of the column to bind. |
| dataSource | TSource | The data source to bind to. |
| sourceProp | String | The property of the data source to bind to the column. |
| parse | Func<DataGridViewCellParsingEventArgs, Object> | Optional. A function to parse cell values. Default is null. |
| format | Func<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");
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.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the DataGridView component. | |
| TSource | The type of the data source. | |
| grid | TComponent | The DataGridView to bind. |
| columnIndex | Int32 | The index of the column to bind. |
| dataSource | TSource | The data source to bind to. |
| dataMember | String | The data member within the data source to bind to. |
| sourceProp | String | The property of the data source to bind to the column. |
| parse | Func<DataGridViewCellParsingEventArgs, Object> | Optional. A function to parse cell values. Default is null. |
| format | Func<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");
Bind<TComponent, TSource>(grid, columnName, dataSource, sourceProp, parse, format)
Binds a specified column of the DataGridView to a data source using the column name.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the DataGridView component. | |
| TSource | The type of the data source. | |
| grid | TComponent | The DataGridView to bind. |
| columnName | String | The name of the column to bind. |
| dataSource | TSource | The data source to bind to. |
| sourceProp | String | The property of the data source to bind to the column. |
| parse | Func<DataGridViewCellParsingEventArgs, Object> | Optional. A function to parse cell values. Default is null. |
| format | Func<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");
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.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the DataGridView component. | |
| TSource | The type of the data source. | |
| grid | TComponent | The DataGridView to bind. |
| columnName | String | The name of the column to bind. |
| dataSource | TSource | The data source to bind to. |
| dataMember | String | The data member within the data source to bind to. |
| sourceProp | String | The property of the data source to bind to the column. |
| parse | Func<DataGridViewCellParsingEventArgs, Object> | Optional. A function to parse cell values. Default is null. |
| format | Func<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");
Bind<TComponent, TSource>(grid, column, dataSource, sourceProp, parse, format)
Binds a specified DataGridViewColumn to a data source.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the DataGridView component. | |
| TSource | The type of the data source. | |
| grid | TComponent | The DataGridView to bind. |
| column | DataGridViewColumn | The DataGridViewColumn to bind. |
| dataSource | TSource | The data source to bind to. |
| sourceProp | String | The property of the data source to bind to the column. |
| parse | Func<DataGridViewCellParsingEventArgs, Object> | Optional. A function to parse cell values. Default is null. |
| format | Func<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");
Bind<TComponent, TSource>(grid, column, dataSource, dataMember, sourceProp, parse, format)
Binds a specified DataGridViewColumn to a data source with a data member.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the DataGridView component. | |
| TSource | The type of the data source. | |
| grid | TComponent | The DataGridView to bind. |
| column | DataGridViewColumn | The DataGridViewColumn to bind. |
| dataSource | TSource | The data source to bind to. |
| dataMember | String | The data member within the data source to bind to. |
| sourceProp | String | The property of the data source to bind to the column. |
| parse | Func<DataGridViewCellParsingEventArgs, Object> | Optional. A function to parse cell values. Default is null. |
| format | Func<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");
Bind<TComponent, TSource>(listView, columnName, dataSource, sourceProp)
Binds a data source to a specified column in a ListView.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the ListView component. | |
| TSource | The type of the data source. | |
| listView | TComponent | The ListView component to bind the data source to. |
| columnName | String | The name of the column to bind the data source to. |
| dataSource | TSource | The data source to bind. |
| sourceProp | String | The 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.
Bind<TComponent, TSource>(listView, columnName, dataSource, dataMember, sourceProp)
Binds a data source to a specified column in a ListView with a specified data member.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the ListView component. | |
| TSource | The type of the data source. | |
| listView | TComponent | The ListView component to bind the data source to. |
| columnName | String | The name of the column to bind the data source to. |
| dataSource | TSource | The data source to bind. |
| dataMember | String | The data member of the data source to bind. |
| sourceProp | String | The 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.
Bind<TComponent, TSource>(listView, column, dataSource, sourceProp)
Binds a data source to a specified column in a ListView.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the ListView component. | |
| TSource | The type of the data source. | |
| listView | TComponent | The ListView component to bind the data source to. |
| column | ColumnHeader | The column to bind the data source to. |
| dataSource | TSource | The data source to bind. |
| sourceProp | String | The 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:
- ArgumentNullException Thrown when the specified column is null.
Bind<TComponent, TSource>(listView, column, dataSource, dataMember, sourceProp)
Binds a data source to a specified column in a ListView with a specified data member.
| Parameter | Type | Description |
|---|---|---|
| TComponent | The type of the ListView component. | |
| TSource | The type of the data source. | |
| listView | TComponent | The ListView component to bind the data source to. |
| column | ColumnHeader | The column to bind the data source to. |
| dataSource | TSource | The data source to bind. |
| dataMember | String | The data member of the data source to bind. |
| sourceProp | String | The 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:
- ArgumentNullException Thrown when the specified column is null.