Deleting an Item 'remotely'...

BlitzPlus Forums/BlitzPlus Beginners Area/Deleting an Item 'remotely'...

OverDozing(Posted 2005) [#1]
Hey Folks,

Yeah me again!
I am having some troubles again, here the thing:
I need to delete an item from a ListBox without selecting it , from an other Panel without showing the current ListBox gadget where the item is.

I can do that on Tree Views but I have no idea how to do that on a Listbox.

The Problem is the Index stuff (RemoveGadgetItem gadget,index), I cannot know the index when I am creating an item and then I cannot store it somewhere to find it back later, so I am unable to do my stuff :/

Damn it ! Any help/idea is appreciate !
thank you.


WolRon(Posted 2005) [#2]
I don't see WHY you can't know the index when you create it. I certainly know the indexes of the ones I create.

But if you really can't, couldn't you just delete them all, and then recreate all but the one you need?


OverDozing(Posted 2005) [#3]
Hey,

How do you do to know the index at the creation of an item ?

I thought about deleting everything but the one I dont want anymore, but in this case, I can't do that...

I would be glad to know how you do to know the index at the creation?

Thanks !! :)


WolRon(Posted 2005) [#4]
Because the index always starts at zero. Just use a variable to keep track of the number of indexes or use CountGadgetItems.

window = CreateWindow("test", 100, 100, 300, 500)
gad = CreateListBox(100, 100, 100, 100, window)
button = CreateButton("replace item", 100, 300, 100, 100, window)
For iter = 0 To 5
	AddGadgetItem(gad, iter)
Next

;loop
Repeat
	event = WaitEvent()
	If event = $401 ;gadget action
		Select EventSource()
			;main buttons
			Case button
				item = Rnd(0, 5)
				RemoveGadgetItem(gad, item)
				AddGadgetItem(gad, 99)
		End Select
	EndIf
	If event = $803 ;Close (X) box pressed
		source = EventSource()
		If source = window Then Exit
	EndIf
Forever


AddGadgetItem always adds to the end of the list, and InsertGadgetItem inserts at the index you specify, so either way, you know the index...


OverDozing(Posted 2005) [#5]
Thank you very much ! :)


OverDozing(Posted 2005) [#6]
Hey....

I am still in trouble with my code :(
It seems the index for the Treeview is different because I checked and from one node to an other the numbers arent following:
126571256
126571576
...

What's the hell :(

All I need is a way to find the text of the node that I selected.

See yaa.


MattVonFat(Posted 2005) [#7]
Maybe you could assign each node to a type? Then you could have the name stored in that.

And i think you have the handles to the nodes confused with the indexes. The indexes are different. If you have a list of nodes

Node1 - index = 0
Node2 - index = 1
Node3 - index = 2

but the handles are different. The indexes are given to the nodes in the order they are listed and if Node2 was deleted the Node3 would have index 1.


OverDozing(Posted 2005) [#8]
Right !!!! I see my mistake now !

Yeah the used of types sound good, but how can I retrieve a 'node name' from a type by selecting a node in the tree view ?
The only thing I can bring back from the tree view is the 'handles' But I will not be able to write the 'handles' to my types. right ?

My treeviews are generated/populated from text files via an import button, we arent on the 'tab' where the treeviews are when we import.

I don't see any commands in the treeview commands list that talk about Index ? and in the gadgets commands list, it's specified that the commands aren't to used with treeviews. :(

Any suggestions ?


MattVonFat(Posted 2005) [#9]
If you have a type like

Type treeNode
    Field nodeText
    Field handle
End Type


You add the handle to the type as:

t\handle = AddTreeViewNode("Hello", root)


And then you can use a for each to cycle through until you find a type that matches the handle of the selected node.


OverDozing(Posted 2005) [#10]
Right ! Awesome !! I am so dumb...
Thanks a lot !!! :)