Jump to content

Listbox: Delete selected Item


 Share

Recommended Posts

Hi all,

can anyone take a look at this? I can't get it to delete an Item from the list. :D

FileChangeDir(@ScriptDir)
GUICreate("zzz", 320, 260)
$Listbox1 = GuiSetControl ("list", "", 10,20,300,200)
$AddDir = GUISetControl ("button", "Add Dir", 10,210,100,20)
GuiSetControlNotify()
$DelItem = GUISetControl ("button", "Del Item", 110,210,100,20)
GuiSetControlNotify()
$ClearList = GUISetControl ("button", "Clear List", 210,210,100,20)
GuiSetControlNotify()
;-------------------------------------------------

While GUIMsg() > 0

if GuiRead () = $AddDir Then
$dirpath = FileSelectFolder("Choose a directory.", "", 0)
    If @error <> 1 AND $dirpath <> "" Then
    GUISetControlData($Listbox1, $dirpath)
    EndIf
EndIf

if GuiRead () = $DelItem Then
$selitem = GuiRead($Listbox1)
;;;missing code to remove the selected item from the list
EndIf

if GuiRead () = $ClearList Then
GUISetControlData($Listbox1, "")
EndIf

Wend

If I use "ControlCommand" with the command "DelString", I can only delete the first Item in the List.

Although the Documentation is one of the best I ever saw, I can't find it.

I already searched this Forum and also yahoo.group.

It would also be nice to know: Is it possible to change the value of an item in the list? But thats not the way important as to delete one.

arctor

Link to comment
Share on other sites

If there are no duplicate entries, then you can ead the selected string with GuiRead(). Then use ControlCommand with "FindString" to get the occurence, then you can use that occurence with DelString. It's a long way about it, but it works.

Link to comment
Share on other sites

There are some ways.

One:

You can use GUISetControlData() for refresh with a StringReplace inside.

Hi josbe,

thx for the quick answer.

Can't get the syntax for your suggestion.

But it brought me to another solution.

$selitem = GuiRead($Listbox1)
$item2delete = ControlCommand ( "zzz", "", "ListBox1", "FindString", $selitem)
ControlCommand ( "zzz", "", "ListBox1", "DelString", $item2delete)
This works for me. :D

You can use GUISetControlData() for refresh with a StringReplace inside.

Can you give an example for that? I'm aways looking for solutions, that fits in 1 line. ;-)

There are some ways.

Another one? hehe

arctor

Link to comment
Share on other sites

If there are no duplicate entries, then you can ead the selected string with GuiRead(). ...

Hi Valik,

what you said is exactly what I just found.

I tested it with duplicate and like duplicate entries. It will delete only one of them

arctor

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...