Nevron Open Vision Documentation
Data Sources

A data source is represented by the NDataSource class, which derives from NAttribute. A data source aggregates a NDataTable and exposes methods and properties identical to the properties and methods of NDataTable (see Data Tables for a complete discussion of the API).

The purpose of the NDataSource is thus to aggregate a data table and make it possible to incorporate data tables inside a DOM hierarchy. An instance of the NDataSource class is thus often exposed as property of elements that need to have data binding abilities. The aggregated data table is accessible from the DataTable readonly property. A data source is associated with a data table at data source creation time:

Creating a Data Source

Copy Code
// create a data table with two fields
NMemoryDataTable dataTable = new NMemoryDataTable(
    new NFieldInfo("Name", typeof(string)),
    new NFieldInfo("Birthday", typeof(DateTime)));
           
// fill the data table
dataTable.AddRow("George", new DateTime(1976, 12, 19));
dataTable.AddRow("Andrew", new DateTime(1982, 9, 27));
// create a data source
NDataSource dataSource = new NDataSource(dataTable);

When a data source is deep cloned it copies the aggregated data table by reference. This means that deep cloning a data source produces two data sources that simultaneously reference the same data table:

The Data Table is Deep Cloned by Reference
Copy Code
NMemoryDataTable dataTable = new NMemoryDataTable(
    new NFieldInfo("Name", typeof(string)),
    new NFieldInfo("Birthday", typeof(DateTime)));
NDataSource dataSource1 = new NDataSource(dataTable);
NDataSource dataSource2 = (NDataSource)dataSource1.DeepClone();
Debug.Assert(Object.ReferenceEquals(dataSource1.DataTable, dataSource2.DataTable));

A data table is designed to notify parties interested in changes that occur in the data table, by subscribing for changes via the INDataTableObserver interface. The NDataSource class implements this interface and exposes the following events that let you monitor for changes in the underlying data table:

Event Description

event Function<NDataSourceRowChangedEventArgs> RowInserted

Occurs when a row has been inserted in the data source.

event Function<NDataSourceRowChangedEventArgs> RowRemoved

Occurs when a row has been removed from the data source.

event Function<NDataSourceFieldChangedEventArgs> FieldInserted

Occurs when a field has been inserted in the data source.

event Function<NDataSourceFieldChangedEventArgs> FieldRemoved

Occurs when a field has been removed from the data source.

event Function<NDataSourceFieldRenamedEventArgs> FieldRenamed

Occurs when the name of a field in the data source has changed.

event Function<NDataSourceValueChangedEventArgs> ValueChanged

Occurs when a [row;field] cell value has changed.

event Function<NEventArgs> DataChanged

Occurs when multiple rows have been inserted or removed or when multiple cell values have changed.

event Function<NDataSourceNameChangedEventArgs> NameChanged

Occurs when the name of the data source has changed.

 

 

Send Feedback