How do we facade an object as a DataTable?

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,081
Programming Experience
10+
Suppose I have an object that has 3 string properties and a String array proeprty.

I'd like to facade this object as a datatable such that the number of rows is equal to the length of the array and the number of columns is 4. The column headers would take the names of the properties that they show and the row data for the 3 string properties is repeated for the whole column in the case of the single strings, and for the array, each element individually?

For example, my object has
Album="The Album"
Artist="The Artist"
Genre="The Genre"
Tracks() = New String(){"Track1","track2","track3"}

and i'd like:

VB.NET:
[FONT=Courier New][FONT=Courier New][FONT=Courier New][FONT=Courier New][B]Album     | Artist     | Genre     | Tracks[/B][/FONT]
[/FONT][FONT=Courier New][FONT=Courier New]The Album | The Artist | The Genre | Track1[/FONT]
[FONT=Courier New]The Album | The Artist | The Genre | Track2[/FONT]
[FONT=Courier New]The Album | The Artist | The Genre | Track3[/FONT]

and hence I can assign it to a datagrid, edit it etc..
[/FONT][/FONT][/FONT]
 
Your "object" sounds like it is an collection/array with items that are instance of a serializable class with mentioned properties (3 strings plus a string collection/array), but the collection object itself has to implement IListSource like DataTable in a way that the returned list repeats the 3 'base' properties for each item in its track list.. maybe if you inherit CollectionBase and implement IListSource.GetList in some way?
 
Last edited:
Back
Top