473,327 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Collection Question

I am Making a Collection for categories

There will be three fields

Category Major And Minor
For the Category i need to know what Type it is Expense/income
for the major i need to know the cat id and the major id
and for the minor the cat and the major id

at least i think that is the best way to set it up which is actually my
question
what is the best method for this a datatable which is related a collection
if so which one because i have seen a few of them

I want to be able to use this collection to populate combobox wit h there
perspective fields as wells as list boxs and also i would like to
poplulate a tree with the parent the category the child the major and the
grandchild the minor

for example if the category were groceries the major could be fruits and the
minor would be apples

i was thinking the best way of doing this would be to make a collection of
the three fields and each on have properties but do not know how do to do
this A
and b i dont know enough about collections in vb.net to decide which way
will be the most efficient

any ideas?

WStoreyII
Nov 20 '05 #1
4 1644
Cor
Hi WStorey

Forget the collection, you can absolutly do nothing with it as databinding
and so on.

Dim dt as new datatable(WS)
dim dc1 as new datacolumn("Category")
dim dc2 as new datacolumn("Major")
dim dc3 as new datacolumn("Minor")
dt.columns.add(dc1)
dt.columns.add(dc2)
dt.columns.add(dc3)
dim dr as datarow = dt.newrow
dr("Category")= 1
.....
dt.add(dr)
You have now a datatablewith one row and you can add as much rows as you
wish

dt.rows(0).item(0) gives you 1 in this case.

(All is typed in here so watch typos)

I hope this helps?

Cor
Nov 20 '05 #2
Cor
Hi WStorey

Forget the collection, you can absolutly do nothing with it as databinding
and so on.

Dim dt as new datatable(WS)
dim dc1 as new datacolumn("Category")
dim dc2 as new datacolumn("Major")
dim dc3 as new datacolumn("Minor")
dt.columns.add(dc1)
dt.columns.add(dc2)
dt.columns.add(dc3)
dim dr as datarow = dt.newrow
dr("Category")= 1
.....
dt.add(dr)
You have now a datatablewith one row and you can add as much rows as you
wish

dt.rows(0).item(0) gives you 1 in this case.

(All is typed in here so watch typos)

I hope this helps?

Cor
Nov 20 '05 #3
On Mon, 05 Apr 2004 01:11:06 GMT, "WStoreyII"
<pa**********@sbcglobal.net> wrote:
I am Making a Collection for categories

There will be three fields

Category Major And Minor
For the Category i need to know what Type it is Expense/income
for the major i need to know the cat id and the major id
and for the minor the cat and the major id

at least i think that is the best way to set it up which is actually my
question
what is the best method for this a datatable which is related a collection
if so which one because i have seen a few of them

I want to be able to use this collection to populate combobox wit h there
perspective fields as wells as list boxs and also i would like to
poplulate a tree with the parent the category the child the major and the
grandchild the minor

for example if the category were groceries the major could be fruits and the
minor would be apples

i was thinking the best way of doing this would be to make a collection of
the three fields and each on have properties but do not know how do to do
this A
and b i dont know enough about collections in vb.net to decide which way
will be the most efficient

any ideas?

WStoreyII


Getting the taxonomy right is an important part of any system design.
If I were you, I would consider implementing a standard tree structure
for your categories in a table, thus:

Table: CATEGORY
CategoryID int (not null - PRIMARY KEY)
ParentCategoryID int (allow null)
CategoryName string
TypeCode int (1=expense,2=income etc.)

Using your terminology: a Major category is one where the
ParentCategoryID is null (or zero, if you prefer), all others are
Minor categories.

As you can see, you can implement a deeper tree structure at a later
date, if you need to, simply by changing the contents of the database.
A tree view would be populated simply by executing the SQL:

SELECT * FROM category ORDER BY ParentCategoryID,CategoryName

That would guarantee that all the parent categories ("major") are read
first, and all categories appear in alphabetical order, at every tree
depth. There's no need to test to see if the certain TreeNode exists,
as the ORDER BY has guaranteed it.

A Category object would expose the following properties:

ID int
ParentCategory Category
Name String
Type int (or whatever)
SubCategories CategoryCollection

Finally, implement the CategoryCollection (inherit from
CollectionBase). I recommend implementing two constructors:

sub new CategoryCollection(), and
sub new CategoryCollection(ownerCategory as Category)

This way, you can update your database when someone uses the
construct:

myCategory.SubCategories.Add( aNewCategory )

Just a couple of quick points:

1) Cache your category objects - they tend to be used much, much more
often than they are changed.
2) Although possible, you do not need to implement a TreeCollection of
some sort. The basic CategoryCollection will suffice.
3) If you're implementing a multi-lingual system, factor the
CategoryName field into a different table (or build a view over the
table and use that instead).

hth,

Andy


Nov 20 '05 #4
On Mon, 05 Apr 2004 01:11:06 GMT, "WStoreyII"
<pa**********@sbcglobal.net> wrote:
I am Making a Collection for categories

There will be three fields

Category Major And Minor
For the Category i need to know what Type it is Expense/income
for the major i need to know the cat id and the major id
and for the minor the cat and the major id

at least i think that is the best way to set it up which is actually my
question
what is the best method for this a datatable which is related a collection
if so which one because i have seen a few of them

I want to be able to use this collection to populate combobox wit h there
perspective fields as wells as list boxs and also i would like to
poplulate a tree with the parent the category the child the major and the
grandchild the minor

for example if the category were groceries the major could be fruits and the
minor would be apples

i was thinking the best way of doing this would be to make a collection of
the three fields and each on have properties but do not know how do to do
this A
and b i dont know enough about collections in vb.net to decide which way
will be the most efficient

any ideas?

WStoreyII


Getting the taxonomy right is an important part of any system design.
If I were you, I would consider implementing a standard tree structure
for your categories in a table, thus:

Table: CATEGORY
CategoryID int (not null - PRIMARY KEY)
ParentCategoryID int (allow null)
CategoryName string
TypeCode int (1=expense,2=income etc.)

Using your terminology: a Major category is one where the
ParentCategoryID is null (or zero, if you prefer), all others are
Minor categories.

As you can see, you can implement a deeper tree structure at a later
date, if you need to, simply by changing the contents of the database.
A tree view would be populated simply by executing the SQL:

SELECT * FROM category ORDER BY ParentCategoryID,CategoryName

That would guarantee that all the parent categories ("major") are read
first, and all categories appear in alphabetical order, at every tree
depth. There's no need to test to see if the certain TreeNode exists,
as the ORDER BY has guaranteed it.

A Category object would expose the following properties:

ID int
ParentCategory Category
Name String
Type int (or whatever)
SubCategories CategoryCollection

Finally, implement the CategoryCollection (inherit from
CollectionBase). I recommend implementing two constructors:

sub new CategoryCollection(), and
sub new CategoryCollection(ownerCategory as Category)

This way, you can update your database when someone uses the
construct:

myCategory.SubCategories.Add( aNewCategory )

Just a couple of quick points:

1) Cache your category objects - they tend to be used much, much more
often than they are changed.
2) Although possible, you do not need to implement a TreeCollection of
some sort. The basic CategoryCollection will suffice.
3) If you're implementing a multi-lingual system, factor the
CategoryName field into a different table (or build a view over the
table and use that instead).

hth,

Andy


Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
5
by: Kurt Bauer | last post by:
I have an ASP group calendar application which pulls calendar data from Exchange via webdav into an XML string. I then loop the XML nodes to populate a collection of appointments. Finally I use...
18
by: Scott | last post by:
I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are...
7
by: Pete Davis | last post by:
A different question this time. I have a DataGrid bound to a collection. Is there any way for me to allow sorting? The DataGrid.AllowSorting=true doesn't work, but that's probably because it can't...
4
by: bkazlak | last post by:
Hello, I have a quick question might help me understand garbage collection. let's say I'm having a static collection of objects in one class, so this collection should be cached and present...
3
by: JJ | last post by:
Hi, I noticed in a sample app source code that the app made use of a class for example a user class and then had the user objects that got created stuffed into a user collection. I was wondering...
16
by: Ben Hannon | last post by:
Hi, I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of the VB6 hassles with cloning and serializing an object). All my classes I need cloneable/serializable are now in a...
34
by: Craig Buchanan | last post by:
Which vb.net object is the best match for the vb6 collection class? Specifically, I would like to be able to access the Item property with an index or a key string. I wrote my own class that...
54
by: MLH | last post by:
I use A97 and do not always insert line numbers while writing procedures. I find it necessary to go back and add them later to aid in debugging. Nearly 3 years ago, something was mentioned in...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.