Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a node to TreeView - get Invalid key error

Status
Not open for further replies.

JohnBates

MIS
Feb 27, 2000
1,995
US
Hello again,

This Set newNode stmt is giving error 35603 "Invalid key"

The node key is the 3rd argument which is rs!model_number

The model number is char data type - the value i not always numeric.

I checked the value in ParentNode - it contains the order number as it should.

Does the key have to be numeric ??

Private Sub AddNode(ByRef newNode As node, ByRef ParentNode As node, ByRef rs As ADODB.Recordset)

'Set stmt gives Invalid key error

Set newNode = tvwDB.Nodes.Add(ParentNode, _
tvwChild, rs!model_Number, rs!Quantity_Ordered, _
rs!Quantity_Loaded, "smlBook") 'smlBook is an icon

End Sub

Thanks for your help, John


 
OK, I've found a couple of things that may be causing the Invalid Key error.

1. According to VB Documentation, a nodes Key must be a unique value. Mine is model_number. The same model_number can exist in several customer orders.

- I can derive a unique key by stringing the order_number (which is ParentNode in my case) + model_number.
?? How do I do this ??

2. I'm using 1 too many arguments in my AddNode stmt.... I need to remove rs!Quantity_Loaded


Please help me with # 1.

Thanks, John
 

What may be easier, not to dissuade you in your method, but use a counter. Now for your parent node & quantity.

This is only one way to get what you want
[tt]
Option Explicit

Private Sub Form_Load()

Dim N As Node, C As Node, P As Node

'first you add the parent nodes (do while...)
Set N = TV.Nodes.Add(, , "A1", "Top Node")
'loop

'then you select the node you want to add children to (you will have to figure out how to do this or you can do this while in the loop above and then add its children)
N.Selected = True

'then you set a node object to the one selected (no need to do this if you are populating the children in the loop above)
Set P = TV.Nodes.Item(TV.SelectedItem.Index)

'then you add your child nodes
Set C = TV.Nodes.Add(P.Key, tvwChild, P.Key & "B1", "Child Item")

'if you are adding the children in the loop above then this is one way to add the children
'Set C = TV.Nodes.Add(N.Key, tvwChild, N.Key & "B1", "Child Item")

C.EnsureVisible

End Sub
[/tt]

I hope this helps, Good Luck

 
I think that you can't have a numeric key,

it has to start with a character, as vb5prgrmr said

Transcend
[gorgeous]
 
Thanks vb5prgrmr and Transcend,

I appended the order number, which always begins with a character, to the front of my key field (model number). This way, the key is always unique because our orders never contains duplicate model numbers.

Thanks, John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top