TreeView.Clear() method not clearing keys?
Posted
#1
(In Topic #1328)
Regular

My main form's only TreeView displays added icon entries fine, but when I come to clear it for a fresh set of icon additions, I get an error "key already used"
Am I doing something wrong? Can I clear the keys without having to loop through all the entries (potentially hundreds), deleting them?!
Thanks,
C.
Posted
Guru

Nothing will happen to your key key2 key3 variables they will be whatever you set them to.
this code..
Code (gambas)
- TreeView1.Add("Key1", "Key1")
- TreeView1.Clear
- TreeView1.Add("Key1", "Key1")
TreeView.Clear DOES clear the keys
The keys are stored in TreeView1.Keys
the Key you provide in TreeView1.Add(Key, Text, Pic) gives the TreeView item an identifier
Eg.
You understand by "Key" it means a unique name ,nothing to do with keyboard yes?
the code…
TreeView1.Add(Key2, "Key2")
means Key2 must be a string variable holding a key name like Dim Key2 As String = "Keyname2"
post more complete code so we can see the errors better and not try to guess
Posted
Guru

To make a variable (that's not an object) have its value changed in a function parameter the ByRef keyword must be used on both sides of the command.
eg..
if you do not see the ByRef then a non object datatype will never be affected.
object datatypes and arrays work different as they are already pointers.
for example the following works fine without ByRef
120
130
Hope that makes sense ,, and helps
Posted
Regular

…This 'error' case was my inattentive debugging, and garbage-In > garbage-Out data (a badly constructed .json input file :roll: )
so I was adding clashing keys AFTER my treeView.clear !
The byRef usage is new to me, so an additional way of changing values beyond a function's Return expression
Thanks again.
C.
1 guest and 0 members have just viewed this.


