Create a custom data source

xiaoxiao2021-03-06  66

See a use of CollectionBase to create custom data for the parent class

Example of the source:

Using system;

Namespace custom data source

{

///

// / custom data source

///

Public Class CusDataSource: System.collections.collectionb

ASE

{

Public CusDataSource ()

{

For (int i = 0; i <10; i )

{

Base.innerList.Add (New Element ("a [{0}]", i));

}

}

}

Public Class ELEMENT

{

PRIVATE STRING NAME;

Public String Valuename

{

Get {return name;}

}

Private int value;

Public Int Value

{

Get {return;}

}

Public Element (int Val, String Nam)

{

Name = NAM;

VALU = VAL;

}

}

}

Then we new CusDataSource and bind 2 columns on the DataGrid: Value and Name;

We can also create custom data sources by implementing ILISTSOURCE or IENUMERABLE interfaces, more flexible:

Using system;

Namespace PersonalTest

{

///

A summary description of /// source.

///

Public class source: system.componentmodel.ilistsou

RCE

{

PRIVATE DATA D = New Data ();

Public Source ()

{For (int i = 0; i <10; i ) {