How does DataTable work... really...

AlexCode

Well-known member
Joined
Jul 7, 2003
Messages
931
Location
Portugal
Hi...

I want to undestand how DataTable works when it presents data on a DataGrid.
So:
1. DataTable have 2 collections that interest me:
> Columns
> Rows
2. DataRow object have only one constructor and its pivate.
This means that this object can only be created thru Reflection.
3. Inspecting a DataRow object at run-time, it seems that this object is, in fact, a collection, from where we van retrieve data thru index or name.
4. Now... How can we have a collection (Rows) witch each item is a collection (DataRow) and still the DataGrid can grab the column name and put it on the column header and grab the value and put it on the cell?

The closest I came to this scenario was to have a collection that implements IListSource and its items be a class with public properties.
This way, the DataGrid picks the property name as the column header caption and the property value for the cell...

This isnt quite the same, cause then I cant change the ColumnName like I can on the DataTable structure...

It seems that it gets the schema from the Columns collection and the data from the Rows collection... but how can this be donne?


Thanks in advance!

Alex :P
 
Im not going to go into the details of your post, but you should note that whenever you make a DataTable the DataSource of a DataGrid, the grid is actually bound to a DataView, specifically the DefaultView of the DataTable.
 
Ok... now Im on the right path...

The DataTable implements IListSource, so it has a GetList function that is the one that really returns the collection that is shown on the DataGrid...
I wasnt expecting to see that what DataTable hides behind the scenes is a DataView.

Yeah...

Now... why a DataView?
Simple... because it implements the real core interface that let it do what it does... ITypedList.
Simply put, ITypedList lets you present data based on 2 arrays, one for schema and the other one for data... just what I needed.

Im gonna do some testing on that...
ITypedList have a GetItemProperties function that is a little tricky.

If anyone have any info abou ITyped List I can use I would be gratefull...

Alex :p
 
Back
Top