Results 1 to 5 of 5

Thread: How to create strongly typed collection without designer?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    24

    How to create strongly typed collection without designer?

    I'd like to create strongly typed collection for storing data in tables. is it possible?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to create strongly typed collection without designer?

    Creating a strongly-typed collection is easy:
    vb.net Code:
    1. Public Class ThingCollection
    2.     Inherits System.Collections.ObjectModel.Collection(Of Thing)
    3. End Class
    That's all you need to get all the standard collection functionality. If you need custom behaviour then the Collection(Of T) class provides methods you can override to do that, plus you can add your own members.

    That said, I have no idea what you mean by "for storing in tables". If the data is in a collection then what's the table for? Do you mean a database? Do you mean displaying to the user in a grid? Please provide a full and clear description up front in future. One sentence is rarely enough to convey the full picture to people who have no previous idea of what you're trying to achieve.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    24

    Re: How to create strongly typed collection without designer?

    I mean collection like DataTable with some collumns, but I want it to be strongly typed. I want to use data from this collection without conversion.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to create strongly typed collection without designer?

    Then all you need is a strongly-typed collection, as I've demonstrated. Your Thing class will have a property for each data item you want to store. Now, I've just used "Thing" and "ThingCollection" as examples. You would name your classes after whatever the items are supposed to represent.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    24

    Re: How to create strongly typed collection without designer?

    thanks, i'll try to do it.

Posting Permissions

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



Click Here to Expand Forum to Full Width