Creating a custom DataTableCollection object

Results 1 to 2 of 2

Thread: Creating a custom DataTableCollection object

  1. #1
    Join Date
    Dec 1969

    Default Creating a custom DataTableCollection object

    I have extended the functionality of DataTable just a bit to create an RNDataTable object.<BR><BR>I want to create an RNDataTableCollection object as well, and I&#039;ve done this so far by inheriting from InternalDataCollectionBase (which is what it appears DataTableCollection inherits from).<BR><BR>I also want to be able to access the table using the notation:<BR><BR>myRNTableCollection.Tables["tableName"];<BR><BR>In my RNDataTableCollection, I have the following property:<BR><BR>[code language="C#"]<BR>public RNDataTable this[int index]<BR>{<BR> get { return (RNDataTable)List[index]; }<BR> set { List[index] = value; }<BR>}<BR>[/code]<BR><BR>That works fine for accessing an RNDataTable based on its index value, but how would I implement my initial goal (of accessing it based on its tablename).<BR><BR>So far all I could come up with is this:<BR><BR>[code language="C#"]<BR>public RNDataTable this[string _tableName]<BR>{<BR> get<BR> {<BR> foreach (RNDataTable table in this.List)<BR> if (table.TableName == _tableName)<BR> return this[IndexOf(table)];<BR><BR> // no table with that name was found, return null<BR> return null;<BR> }<BR>}<BR>[/code]<BR><BR>There&#039;s got be a better way. Anyone know what it is?

  2. #2
    Join Date
    Dec 1969

    Default Well, if you read the documentation...

    ...for InternalDataCollectionBase, you see that the LIST member is an ArrayList. So you can use any of the methods available on ArrayList. Including IndexOf.<BR> this.List[ this.List.IndexOf(_tablename) ]<BR>??? does that work???<BR><BR>I do have to ask why you are bothering to inherit from InternalDataCollectionBase instead of just using an ArrayList directly. Is there something else in that class that is of value to you?<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts