Classes
Class | Description | |
---|---|---|
CompositeFieldAttribute |
Specifies that the object property is composite.
| |
CompositeObjectAccessor |
Accessor to composite data objects
| |
CustomTypeDescriptorAccessor |
Wraps an object the ICustomTypeDescriptor type.
| |
DataObjectAccessor |
Wraps an object of arbitrary class and provides access to it via reflection. Can be a part of event-driven model.
| |
DataObjectAccessorBase |
Base data accessor
| |
DataRowAccessor |
Wraps an object of the DataRow type.
| |
DictionaryDataAccessor |
Wraps IDictionary<string, object>.
| |
EnumerableDataAccessor |
Wraps enumerable objects.
| |
FieldAttribute |
Enables property identifier changes.
| |
FieldChangedEventArgs |
Contains information about updated IDataField | |
Getter<(Of <(<'T>)>)> |
Gets a value of a data object property
| |
HierarchicalDataAccessor |
Provides an access to data containing hierarchical fields
| |
HierarchicalFieldAttribute |
Indicates that an object or a collection of objects returned by the property should be added to the grid as children of the current data object
| |
ListDataAccessor |
Wraps IList objects.
| |
PrimitiveTypeAccessor |
Wraps primitive object types such as int, double, etc...
| |
ThreadSafeBindingList<(Of <(<'T>)>)> |
Threadsafe implementation of BindingList<(Of <(<'T>)>)> | |
UnboundValueAccessor |
Collection of IDataField objects that is populated when Grid requires data fields.
| |
ValueGetter |
A cache that keep a value returned from data object property.
|
Interfaces
Interface | Description | |
---|---|---|
IDataAccessor |
Provides uniform access to data of various types (objects of custom classes, rows in data tables, lists, dictionaries...).
| |
IDataField |
Field of IDataAccessor.
Enables a programmer to get or modify value of the IDataAccessor. Typically, this class can represent a property of a data object, a value in a collection, etc.
| |
IGetAccelerator |
Accelerates getting values from properties.
| |
IGetter |
Gets a value of a data object property.
|
Delegates
Delegate | Description | |
---|---|---|
Getter<(Of <(<'T>)>)>..::..GetterDelegate |
A delegate that gets property value.
|
Remarks
.Net Grid is able to manipulate various data types, including user defined classes, string arrays or other objects, IList<(Of <(<'T>)>)>, IDictionary<(Of <(<'TKey, TValue>)>)>, where K is a string identifier or some other type. As you remember, all this broad range of data can be inserted into the .Net Grid through the Grid.Rows.Add(object) / Row.Add(object). Besides that, the grid can be connected to a data source that implements IList, IListSource or IBindingList interfaces.
Such broad functionality of the .Net Grid is possible due to the IDataAccessor interface that is one of the most crucial part of the grid. The main purpose of this interface is to normalize presentation of different data types in the grid. There are lots of implementations of IDataAccessor interface. This way, a programmer can add his own implementation to broaden the list of data types that can be used by the .Net Grid. When you call Grid.Rows.Add(object 'your object'), an implementation of the IDataAccessor interface is created implicitly for 'your object' and the .Net Grid works with it only via the IDataAccessor proxy, making no difference between the data types.
Intrinsically, IDataAccessor interface is nothing more than a simple 'container' for data object fields (IDataField object), that should be displayed in a grid cell. Each field contains an identifier, a name, a description, information about formats and editors, and it can be used to get values from a data object or to set values. Please note, that for different objects the process of getting or setting values of a data object may vary. For user-defined classes you can use the reflection mechanism to get or set values. For IList<(Of <(<'T>)>)> the grid gets them with a certain index; for IDictionary<string, object> with a string key so on. IDataAccessor may support or not support data field identifiers it merely depends on its nature. If an object of user defined class is inserted into the grid, than its property name become the identifiers in the IDataAccessor by default. However, sometimes identifiers may be absent, e.g. if you you use an IList<(Of <(<'T>)>)> object as a parameter of the method Grid.Rows.Add(object 'your object'). In such case, to display data in cells the .Net Grid uses indices of IList<(Of <(<'T>)>)> and index of the column which is calculated when it is inserted into the header.
IDataAccessor is able to subscribe to events of data objects implementing INotifyPropertyChanged interface and transfer them into the grid. This approach is widely used in the event-driven model. Please note, that all implementations of the IDataAccessor interface in the Dapfor's package are thread-safe!
Copy | |
---|---|
public void DataLevelAbstraction(Grid grid) { //Initialize the header grid.Headers.Add(new Header()); grid.Headers[0].Add(new Column("Price")); grid.Headers[0].Add(new Column("Quantity")); //Add a data object to the grid. The object is implicitly wrapped by the DataObjectAccessor Product product = new Product(); grid.Rows.Add(new Product()); //Add a data object which is explicitly wrapped by the DataObjectAccessor to the grid. grid.Rows.Add(new DataObjectAccessor(new Product())); //Add a collection of values to the grid. //Because of this collection implements IList, it will be implicitly wrapped by the ListDataAccessor grid.Rows.Add(new double[] {123, 12, 45}); //Add a dictionary of values to the grid. Hashtable hashTable = new Hashtable(); hashTable.Add("Price", 10); grid.Rows.Add(hashTable); //Add an empty row to the grid Row row = grid.Rows.Add(new UnboundValueAccessor()); //Set some values for this row row["Price"].Value = 10; //Build some hierarchy for the already added row row.Add(new int[] {10, 11, 12}); //Now we will update the product. The property of Product fires the notification //and the grid will automatically refresh the cell, scroll and filter corresponding row if needed. product.Price = 98.6; //Update the product in other thread - this is safe. The grid will synchronize threads without blocking the calling thread //and refresh, sort and filter the corresponding row. ThreadPool.QueueUserWorkItem(delegate { product.Price = 102.7; }); } |