frustrating array/dictionary problem!

Anti-Rich

Well-known member
Joined
Jul 1, 2006
Messages
325
Location
Perth, Australia
Programming Experience
1-3
hello everyone,

at the moment i am trying to grab some information from the database and put it into a custom control called 'TreeListView' (any guesses what it does? :p)...

the data in question is pick rate information in a warehouse. so basically the person is given a number of vouchers with the total number of items on the vouchers, and when they finish they also record the hours they spent here...
so the table structure is like this:

LocationID
PickDate
EmployeeID
GridID (location within in the warehouse)
PickHours
PickVouchers
PickItems

There is no primary key as the entry system on the front end needs to allow for multiple entries by the same person at the same grid location on the same day. i was thinking i should just give it a basic primary key of an incrementing integer... is this a good idea or should i just leave it as it is?

anyway, i need the information to drill down in the treelistview like so:

LocationID
--> Pick Date
--> Grid ID
Employee : Total Pick Hours : Total Vouchers : Total Items

So, the problem is how should i store all of this data locally so i can populate the treelistview at will? i know the sql i need to GET the data itself, but as to how to store it properly i am COMPLETELY stumped... i have been working on this all morning and i still havent come up with a solution! for similar things in the past i have used Dictionaries (god bless cjard for introducing me to those! ), but i feel that there is too much data and doing it using a dictionary much more complex than it needs to be (it would be a case of dictionaries within dictionaries within dictionaries!)...

i cant use a selecteditem because the expand event on the treelistview to grab data upon request (which would be MUCH easier if the control implemented it!) as it doesnt recognise that something has been clicked or selected when you expand a node/item

does anyone have any ideas on how i can approach this?

cheers all
adam
 
TreeView

David,

Here is a code I use to populate a treeview, using data stored in a text file (in a CSV format - comma separated values). You can adapt it to any database you like.

For the code below to work, just create a text file with notepad, write the following and save it as Locs.txt:

Warehouse 1, Employee 1, 3 hours
Warehouse 1, Employee 2, 4 hours
Warehouse 1, Employee 3, 2 hours
Warehouse 2, Employee 1, 7 hours
Warehouse 2, Employee 1, 2 hours
Warehouse 3, Employee 1, 6 hours

Take care,

Luis

-----------------------------

Private Sub PopulateTreeView(ByVal NomeArq As String, ByVal trv As TreeView)

Dim line As String
Dim read_file() As String = {""}

Try
read_file = File.ReadAllLines("Locs.txt")
Catch ex As FileNotFoundException
MsgBox("File Locs.vtc not found")
Catch ex1 As Exception
MsgBox(ex1.Message)
End Try

For Each line In read_file
BuildTreeView(trv.Nodes, Split(line, ","), 0)
Next

End Sub

'---------------------------------------------------------------------

Private Sub BuildTreeView(ByVal node_parent As TreeNodeCollection, ByVal fields() As String, ByVal field_number As Integer)

' get out if all fields have been used
If field_number > fields.GetUpperBound(0) Then Exit Sub

' search for node_chile
Dim found_it As Boolean
' rund through each node
For Each child_node As TreeNode In node_parent
If child_node.Text = fields(field_number) Then
' if found, use recursion
BuildTreeView(child_node.Nodes, fields, field_number + 1)
found_it = True
End If
Next child_node

If Not found_it Then
' does not exist, so create one
Dim new_node As TreeNode = node_parent.Add (fields(field_number))
'new_node.EnsureVisible()

BuildTreeView(new_node.Nodes, fields, field_number + 1)
End If
End Sub
 
hello everyone,

at the moment i am trying to grab some information from the database and put it into a custom control called 'TreeListView' (any guesses what it does? :p)...

the data in question is pick rate information in a warehouse. so basically the person is given a number of vouchers with the total number of items on the vouchers, and when they finish they also record the hours they spent here...
so the table structure is like this:

LocationID
PickDate
EmployeeID
GridID (location within in the warehouse)
PickHours
PickVouchers
PickItems

There is no primary key as the entry system on the front end needs to allow for multiple entries by the same person at the same grid location on the same day.
If you need to update or delete items from your warehouse, you MUST have a primary key. i.e. you MUST ensure there is a way to uniquely refer to a particular item in the warehouse. If the house simply colelcts items and never uses or disposes of them you dont need a primary key

i was thinking i should just give it a basic primary key of an incrementing integer... is this a good idea or should i just leave it as it is?
Its usually better to try and find a primary key within the data, but autonumbers can work if all youre doing is wanting to get the user to pick an item to update or delete. THing is; how do they pick the unique item to edit? Follow that search logic and you have your primary key!

anyway, i need the information to drill down in the treelistview like so:

LocationID
--> Pick Date
--> Grid ID
Employee : Total Pick Hours : Total Vouchers : Total Items

So, the problem is how should i store all of this data locally
You dont store all data locally. You store only what is needed.

Make several queries:

SELECT locationID FROM warehouse GROUP BY locationID
SELECT pick_date FROM warehouse WHERE locationID = @locationIDParam GROUP BY pick_date
SELECT grid_id FROM warehouse WHERE locationID = @locationIDParam AND pick_date = @pickDateParam GROUP BY grid_id
SELECT * FROM warehouse WHERE locationID = @locationIDParam AND pick_date = @pickDateParam AND grid_id = @gridIDParam


The first 3 are used to build the nodes. Call the first one first and put the nodes. When the user expands, run the second query and insert the node value. When the user expands again, run the third query and the 2 node values etc...





so i can populate the treelistview at will? i know the sql i need to GET the data itself, but as to how to store it properly i am COMPLETELY stumped...
I dont know how your treelistview works so i dont know if it supports databinding. You should be looking to the treelistview doc for help

it would be a case of dictionaries within dictionaries within dictionaries!)...
That's called a "database" with little things called "indexes" ;)

i cant use a selecteditem because the expand event on the treelistview to grab data upon request (which would be MUCH easier if the control implemented it!) as it doesnt recognise that something has been clicked or selected when you expand a node/item
Well, youre pretty screwed then. Find a better control that fires some events when the user interacts with it
 
Back
Top