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
/// summary>
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.
/// summary>
Public class source: system.componentmodel.ilistsou
RCE
{
PRIVATE DATA D = New Data ();
Public Source ()
{For (int i = 0; i <10; i ) {
script>
D.Add (New DataItem (I, String.Format)))));
}
}
#Region ILISTSOURCE member
Public system.collections.ilist getList ()
{
// Todo: Add Source.getList implementation
Return D;
}
Public Bool ContainSlistCollection
{
get
{
// Todo: Add Source.ContainSlistCollection getter implementation
Return False;
}
}
#ndregion
}
Public class data: system.collections.ilist, system.collections.ienumerator
{
Protected system.collections.Arraylist_dataitems;
protected int _ptr = 0;
script> public data ()
{
_Dataitems = new system.collections.ArrayList ();
}
#Region IList member
Public Bool IsReadonly
{
get
{
// Todo: Add data.isreadonly getter to implement Return False;
}
}
Public Object this [int index]
{
get
{
Return_DataItems [index];
}
set
{
_Dataitems [index] = value;
script>}
}
Public Void Removeat (int index)
{
IF (INDEX> = 0 && index <_dataitems.count)
_Dataitems.removeat (index);
}
Public void insert (int index, object value)
{
IF (INDEX> = 0 && index <_dataitems.count)
{
_DataItems.insert (Index, Value)
;
}
}
Public Void Remove (Object Value)
{
_DataItems.remove (Value);
}
Public Bool Contains (Object Value)
{
Return_DataItems.Contains (Value);
}
Public void clear ()
script> {
_Dataitems.clear ();
}
Public int indexof (Object Value)
{
Return_DataItems.indexof (Value);
}
Public Int Add (Object Value)
{
Return_DataItems.Add (Value);
}
Public Bool IsFixedsize
{
get
{
Return_DataItems.isfixedsize;
}
}
#ndregion
#Region Icollection member
Public Bool Issynchronized
{
get
{
Return False;
}
}
Public Int Count
{
get
{
Return_DataItems.count;
}
}
Public void CopyTo (Array Array, Int Index)
{
}
Public Object Syncroot
{
get
{
Return NULL;
}
script>}
#ndregion
#Region Ienumerable member
Public system.collections.ienumerator geteNumerator ()
{
Return this;
}
#ndregion
#Region Ienumerator member
Public void reset ()
{
_PTR = 0;
}
Public Object Current
{
get
{
Return this [_PTR ];
}
}
Public bool movenext ()
{
IF (_PTR { Return True; script>} Else { This.Reset (); Return False; } } #ndregion } Public Class DataItem