Sign in to follow this  
Followers 0
Chetwood

How to delete several ListViewItems?

8 posts in this topic

Although my new problem stems from this thread I think this subforum is more appropriate since it's about a GUI function. With a bit of tweaking Larry's folder select code I managed to put all folders/isos from a certain folder into a listview which looks like this:

Posted Image

Now I simply want to delete folders/isos by marking them and clicking (-). Problem is that I don't know which controlIDs to use with the GUICtrlDelete ( controlID )-command since I sort of automatically generated the ListViewItems by reusing some code lines from the help file:

$listview = GUICtrlCreateListView("Folders drag & drop", 10, 20, 370, 210,$LVS_NOCOLUMNHEADER)


$search = FileFindFirstFile("*.*")
If $search = -1 Then 
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

$movies=""
$no="0"

While 1
   $folder = FileFindNextFile($search)
   If @error Then ExitLoop
   If StringInStr(FileGetAttrib($folder),"D") or StringInStr($folder,".iso") Then;check if file found is folder or iso
       If $folder="." or $folder=".." Then;ignore occurrences of "." and ".."
       Else
           $movies = $moviefolders & "\" & $folder;prepend folder/iso-names with complete path
           $no = $no + 1;count number of items in listview for later reference
           GUICtrlCreateListViewItem ($movies,$listview);create ListViewItem for any found folder/iso and name it accordingly
           EndIf
   EndIf
WEnd

FileClose($search); Close the search handle

Now this command GUICtrlCreateListViewItem ($movies,$listview) apparently creates a ListViewItem for each folder/iso found and names them with an appropriate controlID. But what is that controlID? And how can I delete several of them? I kinda hoped that when using

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = -3
        Exit
    Case $msg = $remove
        GUICtrlDelete($listview)
    EndSelect
WEnd

AutoIt would automatically realize which ListViewItem is selected and use the corresponding controlID on the $listview. Fatchance :(


MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch

Share this post


Link to post
Share on other sites



While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = -3
        Exit
    Case $msg = $remove
        GUICtrlDelete($listview)
    EndSelect
WEnd

AutoIt would automatically realize which ListViewItem is selected and use the corresponding controlID on the $listview. Fatchance :(

<{POST_SNAPBACK}>

UDF in the beta - Check out

_GUICtrlListViewDeleteItemsSelected($listview)

hth

Hardcopy


Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

Doh, yes it did, thanks. Of course I'm now stuck at the next problem, I wanna mark the line that is currently read from the listview:

Case $msg = $run
        $number=_GUICtrlListViewGetItemCount($listview)
        For $i=0 to $number
            $movie=_GUICtrlListViewGetItemText($listview,$i)
            _GUICtrlListViewSetItemSelState($listview,$i)
            Sleep(5000)
        Next
        ExitLoop

This works as it does add the name of each movie to the variable $list but it does not mark the line that is currently being added.

_GUICtrlListViewSetItemSelState($listview,$i) does not seem to have any effect, how come?


MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch

Share this post


Link to post
Share on other sites

Also, how come that the listviewitems are set to 30 chars?

m:\my main movie folder\movie_a

is shortened to

m:\my main movie folder\mo...

I guess it is because there seem to be two columns in the listview even if I do only use the first (and have no idea how I created the second) and I cannot change their width manually because I use '$LVS_NOCOLUMNHEADER' to turn off the column "header".

You can see that the blue bar marking the items in my screenshot does not cover the whole width and padding blanks to the column heading definition to control initial column size as suggested in the help file does not work. Any ideas how to get rid of the second column?


MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Look at all the _GUICtrlListViewXXXX functions in the help file... Maybe you will notice _GUICtrlListViewSetColumnWidth() and _GUICtrlListViewDeleteColumn() plus many others that can help you...

Edited by Burrup

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

Also be careful of setting styles and extended styles for this will affect how the listview will function, for full row select look at the extended style $LVS_EX_FULLROWSELECT


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Look at all the _GUICtrlListViewXXXX functions in the help file... Maybe you will notice _GUICtrlListViewSetColumnWidth() and _GUICtrlListViewDeleteColumn() plus many others that can help you...

<{POST_SNAPBACK}>

Thanks for the pointer, I already did so but when I did not get any results from using _GUICtrlListViewDeleteColumn($listview,1) which should have deleted the second column I got a bit discouraged. I still don't get what that column's id is since it must have been assigned automatically by the FileFindNextFile command in conjunction with GUICtrlCreateListViewItem ($movies,$listview) as shown in my code example above. Curiously enough _GUICtrlListViewDeleteColumn($listview,0) does delete the first column, so '1' should be the id of the second unwanted one.

Now I've used _GUICtrlListViewSetColumnWidth() to set the first column to fill up the entire listview window which also takes care of the selection width so that I don't need to resort to $LVS_EX_FULLROWSELECT. If anyone knows how to get the id of that columns please let me know, thanks again.


MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch

Share this post


Link to post
Share on other sites

Check _GUICtrlListViewGetColumnOrder() or _GUICtrlListViewGetColumnOrderArray() and see what it returns.


[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
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
Sign in to follow this  
Followers 0