Jump to content

_GUICtrlListView_DeleteItemsSelected w/ Checkboxes


Recommended Posts

_GUICtrlListView_DeleteItemsSelected($listview) works fine to delete items in my listeview if I am "selecting" them by clicking on their name....

What I would like to do, is delete items in my listview based off of what is "checked" and not "selected" in blue.

Also, is there a way disable "selecting", so that only my checkboxes serve a purpose?

Thanks,

Tim

Link to comment
Share on other sites

Have a look at this topic for your first question pertaining to selecting the listview items by checkbox: >link

Have a look at this topic for your second question: >link

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Have a look at this topic for your first question pertaining to selecting the listview items by checkbox: >link

Have a look at this topic for your second question: >link

For my first question, I have this code:

Local $ItemCount = _GUICtrlListView_GetItemCount($listview), $Checked[$ItemCount + 1]
Local $X = 1 ; <<<<<<<<<<<<<< updated code
    For $i = 0 To $ItemCount - 1 ; check all items in the lv and see if any are checked off
        If _GUICtrlListView_GetItemChecked($listview, $i) Then
            _GUICtrlListView_DeleteItem($listview,$i)
        EndIf
    Next
EndFunc

It deletes what is selected, but only 1 at a time. So if I have 5 things selected, I have to hit delete multiple times.

For question 2: I don't need it anymore, since I am using DeleteItem instead of DeleteItemSelected....but I would still like to fix my loop so I only have to press delete once instead of multiple times.

Edited by timdecker
Link to comment
Share on other sites

Have a look at:

_GUICtrlListView_DeleteItemsSelected($listview)

EDIT: My apologies, this does not work with checkboxes.

I'm thinking of a solution.  ^_^

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Why not use the exact same code I gave you in your >other topic to do this? Just use it to delete items instead.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Have a look at:

_GUICtrlListView_DeleteItemsSelected($listview)

EDIT: My apologies, this does not work with checkboxes.

I'm thinking of a solution.  ^_^

Thanks, I am have problems understanding why I have to hit delete multiple times. What's wrong with my loop?

Link to comment
Share on other sites

Why not use the exact same code I gave you in your >other topic to do this? Just use it to delete items instead.

 I did that....

Local $ItemCount = _GUICtrlListView_GetItemCount($listview), $Checked[$ItemCount + 1]
Local $X = 1 ; <<<<<<<<<<<<<< updated code
    For $i = 0 To $ItemCount - 1 ; check all items in the lv and see if any are checked off
        If _GUICtrlListView_GetItemChecked($listview, $i) Then
            _GUICtrlListView_DeleteItem($listview,$i)
        EndIf
    Next
EndFunc

But if I have multiple things selected, I have to hit delete multiple times. Sometimes it deletes one item at a time, sometimes it deletes 3 items, then 2 items, then 4 items....

EDIT: What it seems to be doing, is only deleting 1/2 of it at a time. So if I select 12, it will delete 6, then 3, then 2, then the last 1. How do I get it to delete all 12?

Edited by timdecker
Link to comment
Share on other sites

I did that....

No you didn't, that is not script I posted in #13, that's the code from #7 which won't work as posted for what you're doing. You should look at the full code in #13 where I posted how to identify all of the checked items, put them in an array, and loop through the array to do something with those checked items. You're picking and choosing what code you THINK works without sitting down and seeing how the code ACTUALLY works. If you don't know what the code is doing, you're never going to be able to work this out for yourself.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

No you didn't, that is not script I posted in #13, that's the code from #7 which won't work as posted for what you're doing. You should look at the full code in #13 where I posted how to identify all of the checked items, put them in an array, and loop through the array to do something with those checked items. You're picking and choosing what code you THINK works without sitting down and seeing how the code ACTUALLY works. If you don't know what the code is doing, you're never going to be able to work this out for yourself.

 

I am fairly sure I understand what I am reading for the code....

If you look at my ConsoleWrite statement, it writes the line number of the row I selected.

Local $ItemCount = _GUICtrlListView_GetItemCount($listview), $Checked[$ItemCount + 1]
        Local $X = 1 ; <<<<<<<<<<<<<< updated code
        For $i = 0 To $ItemCount - 1 ; check all items in the lv and see if any are checked off
            If _GUICtrlListView_GetItemChecked($listview, $i) Then
                $Checked[$X] = $i
                $X += 1
                ;ConsoleWrite($Checked[$X])
            EndIf
        Next
        ReDim $Checked[$X]
        $Checked[0] = $X - 1
        If $Checked[0] > 0 Then
            For $rows = 0 To $Checked[0]
                if GUICtrlRead($Checked[$rows]) > 0 then ContinueLoop
                ConsoleWrite($Checked[$rows])
                _GUICtrlListView_DeleteItem($listview,$Checked[$rows])
            Next
        EndIf
EndFunc

What I can't understand is why it delete only 50% of the rows at a time per press of the button...

Edited by timdecker
Link to comment
Share on other sites

In this case you need to loop through the array in reverse, more than likely. Once you delete an item, the lines shift up by one so you're looking at the wrong line the next time through the loop.

Also, what is this line doing?

if GUICtrlRead($Checked[$rows]) > 0 then ContinueLoop

There are no controls that this could possibly work correctly with, the numbers in the $Checked array are listview indexes, not controls, so checking to see if you can read from a control ID that has no connection to your listview makes no sense.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

In this case you need to loop through the array in reverse, more than likely. Once you delete an item, the lines shift up by one so you're looking at the wrong line the next time through the loop.

Also, what is this line doing?

if GUICtrlRead($Checked[$rows]) > 0 then ContinueLoop

There are no controls that this could possibly work correctly with, the numbers in the $Checked array are listview indexes, not controls, so checking to see if you can read from a control ID that has no connection to your listview makes no sense.

 

I honestly think this is all I need:

Local $ItemCount = _GUICtrlListView_GetItemCount($listview), $Checked[$ItemCount + 1]
        For $i = 0 To $ItemCount - 1 ; check all items in the lv and see if any are checked off
            If _GUICtrlListView_GetItemChecked($listview, $i) Then
                ConsoleWrite($i)
            EndIf
        Next

EndFunc

The consoleWrite here, returns the index of the rows. What I am unsure of is how to go in reverse (like you said).

Link to comment
Share on other sites

Tim,

Local $ItemCount = _GUICtrlListView_GetItemCount($listview), $Checked[$ItemCount + 1]
        For $i = $ItemCount - 1 to 0 step -1 ; check all items in the lv and see if any are checked off
            If _GUICtrlListView_GetItemChecked($listview, $i) Then
                ConsoleWrite($i)
            EndIf
        Next

EndFunc

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

 

Tim,

Local $ItemCount = _GUICtrlListView_GetItemCount($listview), $Checked[$ItemCount + 1]
        For $i = $ItemCount - 1 to 0 step -1 ; check all items in the lv and see if any are checked off
            If _GUICtrlListView_GetItemChecked($listview, $i) Then
                ConsoleWrite($i)
            EndIf
        Next

EndFunc

 

Thank you for that kylomas, that worked! I tried multiple variations of that, but I guess not that combo....

 

Could someone explain this to me:

For $i = $ItemCount - 1 to 0 step -1

Thanks!

Tim

Edit: Looking at it it, it makes sense now...but just to clarify the "Step - 1" part is saying to go in reverse, right?

Edited by timdecker
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...