Groups | Blog | Home
all groups > vb.net > february 2006 >

vb.net : Creating a Custom Data Source that implements IList or IListSource


Richard Bysouth
2/8/2006 11:55:27 PM
Hi

I am trying to create an object that I can use to bind to a grid in my Win
app. All of the examples that I have found on custom data sources have the
properties (e.g. FirstNamer, LastName) of the objects making up the columns
in a grid. In my situation however there can be any number of columns.

I have created Row and Column classes, each of which have properties such as
Visible. Columns have a Caption property which should become the text in the
header cell of the grid.

I have built RowCollection and ColumnCollection classes which inherit
Generic List(Of Row/Column).

The missing link though is the class that holds the data values (and which
is bindable). As far as I can work out this would be say a Cell class, which
would have Row, Col and Data properties.

In the past (VB6 days) we were able to achieve this functionality using a
2-dimensional variant array e.g. GridData(Row,Col) - this could be bound
straight to the grid. So I guess what I need is the equivalent of that!

Can anyone point me in the right direction please?

CMM
2/9/2006 3:16:20 AM
This has already been done for you. It's called the DataTable.
DataTables (and Datasets) have nothing to do with "Databases."

Dim dt As New DataTable
dt.AddColumn("MyField")

Dim rw As DataRow = dt.NewRow()
rw.Item("MyField") = "whatever"

dt.Rows.Add(rw)

--
-C. Moya
www.cmoya.com

CMM
2/9/2006 3:23:56 AM
Consider a DataTable a 2 dimensional array with a schema. That's all it
really is.

--
-C. Moya
www.cmoya.com

v-yren NO[at]SPAM microsoft.com (
2/9/2006 1:08:37 PM
Hi,

Thanks for posting!

As Moya mentioned, the DataTable control is designed for the two dimension
data. One is the row and another is the column. Just for your reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatadatatableclasstopic.asp

Creating a DataTable:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconcreatingdatatable.asp

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
Richard Bysouth
2/14/2006 9:13:26 PM
Thanks very much - 2bhonest I think I must have been working too long
recently as this is obvious!! Have used DataTables many times before but (as
you imply) I was always thinking of them as related to Databases!

thanks

[quoted text, click to view]
CMM
2/15/2006 12:46:52 AM
It's common. Very few developers can, in their mind, make the disconnection
between Datasets and databases (pun intended... get it? "disconnection").
Datasets are totally database-unaware. If anything, they're more related to
the System.Xml namespace than the System.Data namespace.

--
-C. Moya
www.cmoya.com
[quoted text, click to view]

AddThis Social Bookmark Button