473,394 Members | 1,714 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,394 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 1648
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.