Jump to content

Unable Delete sel.ted item from listview


Fire
 Share

Recommended Posts

Hi Dears.

I have trouble with list view delete selected item.

Also i searched on forum and i found answer for this in here:(below)

http://www.autoitscript.com/forum/index.php?showtopic=86925&st=0&p=623505&hl=listview%20deleteitem&fromsearch=1&#entry623505

But there it realised with arrays.

also i check Autoit help file no success again:(

Note:In my script i didnt use arrays.I try modify my script like in post but no success.

Trouble is How to delete selected item from Listview.

Note:Also i try _GUICtrlListView_DeleteItemsSelected($List1) and _GUICtrlListView_DeleteItemsSelected(Guictrlgethandle($List1)) no success again.

My Question How to do?What is my mistakes in script?

Thanks to all.

Sorry for awfull English.

Here is: GUI script.

#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=Form1.kxf\Form1.kxf
$Form1_1 = GUICreate("Form1", 998, 551, 203, 109)
$goster ="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run: "
$List1 = GUICtrlCreateList("", 16, 24, 969, 409)
GUICtrlSetData($List1,$goster)
$Button1 = GUICtrlCreateButton("SCAN STARTUP", 72, 464, 105, 33, 0)
$Button2 = GUICtrlCreateButton("DELETE SEL..ENTRY ", 824, 464, 113, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$i ="|"
$a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)
; ikinci key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run-
GUICtrlCreateTabItem("aaaaaa")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            for $i =1 to 20
                $a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)
                $b = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $a)
                
                if $a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i) Then
                    $c = StringReplace($a, "Дополнительные данные отсутствуют", ":-)--->")
                    $d = StringReplace($c, ":-)--->", "")
                    
                    
                    $once =RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run-", $i)
                $alternativ="|HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run- :"
                $onceparam =RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run-", $once)
              
                GUICtrlSetData($List1, '' & $goster &  $d &  "-->" & $B)
                ;GUICtrlSetData($List1, '' & $goster &  $d &  "-->" & $b & $onceparam)
            
                
                                      ;
                
                
                
                
            
EndIf
Next
Case $Button2
    $selecteditem = _GUICtrlListBox_GetSelItems($List1)
    $selecteditem1 = _GUICtrlListBox_DeleteString($List1,$selecteditem)
    ;MsgBox(64, "Debug", "Debug" & _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($List1))) returns TRUE but unable delete selected item. for debug reason
    _GUICtrlListView_DeleteItemsSelected($List1) ;It didnt work with selected item it only delete 1,2,3,4,5,6,7,8 and etc values NOt selected.
    
    
    
    
    ;$selecteditem = _GUICtrlListBox_GetSelItems($List1)
    ;
    ;_GUICtrlListBox_ClickItem($List1, $selecteditem)
    
    ;DllCall("kernel32.dll", "ptr", "ExitProcess") 
    
    
    EndSwitch
WEnd
Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

Wouldn't it be nice if before using any _GuiCtrlListView_* functions, there was at least one ListView control in the GUI...?

;)

Hint: A List, or ListBox, is not the same thing as a ListView control. :evil:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks PsaltyDS

What is terrible for me i know somethink wrong in my code but unable to find it and correct:

For debug $selecteditem (really it returns me selected line from listview) and $uu => $uu =_GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($List1))

i add this MessageBoxA:(case $Button2)

MsgBox(64, "Debud reason for $selecteditem ", "$selecteditem Is => " & $selecteditem &  @CRLF & " $uu is => " &  $uu)

It returns me 2 helpfull data:

1`st is for $selecteditem (It is Valid) and the 2`nd data: TRUE.

All is OK But script is unable delete selected item from Listview.

Is here any other ways for realise this correctly but i dont want realise it with arrays.It isnt possible realize this witout arrays?

I check manual too (i mean Autoit Helpfile) theris many examples but 90% with arrays:(

For example i try this:(no success again)

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>


#Region ### START Koda GUI section ### Form=Form1.kxf\Form1.kxf
$Form1_1 = GUICreate("Form1", 998, 551, 203, 109)
$goster ="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run: "
$List1 = GUICtrlCreateList("", 16, 24, 969, 409)

$Button1 = GUICtrlCreateButton("SCAN STARTUP", 72, 464, 105, 33, 0)
$Button2 = GUICtrlCreateButton("DELETE SEL..ENTRY ", 824, 464, 113, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$i ="|"
$a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)
; ikinci key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run-
GUICtrlCreateTabItem("aaaaaa")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            for $i =1 to 20
                $a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)
                $b = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $a)
                
                if $a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i) Then
                    $c = StringReplace($a, "Дополнительные данные отсутствуют", ":-)--->")
                    $d = StringReplace($c, ":-)--->", "")
                    
                    
                    $once =RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run-", $i)
                $alternativ="|HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run- :"
                $onceparam =RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run-", $once)
              
                GUICtrlSetData($List1, '' & $goster &  $d &  "-->" & $B)
                ;GUICtrlSetData($List1, '' & $goster &  $d &  "-->" & $b & $onceparam)
            
                
                                      ;
                
                
                
                
            
EndIf
Next
Case $Button2
    $selecteditem = GUICtrlRead($List1)
$uu =_GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($List1))
MsgBox(64, "Debud reason for $selecteditem ", "$selecteditem Is => " & $selecteditem &  @CRLF & " $uu is => " &  $uu)
   EndSwitch
WEnd
[size="5"] [/size]
Link to comment
Share on other sites

Quit using _GuiCtrlListView_* functions on a control you created with GuiCtrlCreateList().

And get over your fear of arrays, it's juvenile.

Try this function for deleting all selected items in a ListBox control:

; Deletes selected items
; On success returns number of items deleted (could be 0)
; On error sets @error
Func _GuiCtrlListBox_DeleteSelectedItems($hLB)
    If Not IsHWnd($hLB) Then
        $hLB = GUICtrlGetHandle($hLB)
        If Not IsHWnd($hLB) Then Return SetError(1, 0, 0)
    EndIf
    
    Local $aSel = _GUICtrlListBox_GetSelItems($hLB)
    For $n = 1 To $aSel[0]
        _GUICtrlListBox_DeleteString($hLB, $aSel[$n])
    Next
    
    Return $aSel[0]
EndFunc

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thank you again PsaltyDS

I`ll test it.

But i want understand why this is so complicated in AutoIT.(May be it is complicated for me now.(i`m new in it))

Thanks again.

Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

Thank you again PsaltyDS

I`ll test it.

But i want understand why this is so complicated in AutoIT.(May be it is complicated for me now.(i`m new in it))

Thanks again.

What's complicated about that function?

You're making things complicated for yourself in at least two ways:

1. Trying to use ListView functions on controls that are not ListViews

2. Not using arrays, which greatly simplify things

There is a learning curve to arrays, but it's well worth it. Arrays make hard things easier.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I agree with you PsaltyDS

Please help me in this:(I fix my troubles Thanks to you and to Mat) now i want get data from selected column:Any Tips,Hints will appreciate.

For example i use:

$myparamgetcolumn = _GUICtrlListView_GetSelectedColumn($List1)

How to retrieve data from selected column?

My things is going to retrive data(this is a valuename)(in this case startup entry name(from 2nd column) from selected line(like database) and in future use it with regdelete() funcsion.)

P.S OHH this programm really kill me ;)

Posted Image

Thanks again

Script is here:

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=Form1.kxf\Form1.kxf
$Form1_1 = GUICreate("Form1", 998, 551, 203, 109)
$goster ="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run: "
$List1 = GUICtrlCreateListView("KEY" &"|" & "Name" & "|" & "Entry", 16, 24, 969, 409) ;

;GUICtrlSetData($List1,$goster)
$Button1 = GUICtrlCreateButton("SCAN STARTUP", 72, 464, 105, 33, 0)
$Button2 = GUICtrlCreateButton("DELETE SEL..ENTRY ", 824, 464, 113, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$i ="|"
$a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)
; ikinci key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run-

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
        _GUICtrlListView_DeleteAllItems($List1)
    for $i =1 to 20
                $a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)
                $b = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $a)
                
                if $a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i) Then
                    $c = StringReplace($a, "Дополнительные данные отсутствуют.", "")
                    $d = StringReplace($c, @CRLF, "")
                    
                    
                    
                    $once =RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run-", $i)
                $alternativ="|HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run- :"
                $onceparam =RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run-", $once)
                if $d ="" Then
                    GUICtrlCreateListViewItem("|" &  $d & "|" & $b, $List1)
                    Else              ;else never exist :)
    
    GUICtrlCreateListViewItem($goster & "|" &  $d & "|" & $b, $List1)
    ;MsgBox(64, "sssss",GUICtrlRead($List1))
    
    
    EndIf
    
EndIf

                ;GUICtrlSetData($List1, '' & $goster &  $d &  "-->" & $b)
                 ;GUICtrlSetData($List1, $sData)
                ;GUICtrlSetData($List1, '' & $goster &  $d &  "-->" & $b & $onceparam)
            
            
                                      ;
                
                
                
                
            

Next
Case $Button2
     ;$deleteItem = _GUICtrlListView_GetSelectedIndices(GUICtrlRead($List1))
     $selecteditem = GUICtrlRead($List1)
    
     $delete = _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($List1))
     
     ;GUICtrlSetData($List1, "")
    ; GUICtrlSetData($List1,$delete)            ;maraqli bir shey alinir:)
     ;stringreplace(GUICtrlRead($List1),$selecteditem, "Pozuldu!"))    
     ;_GUICtrlListView_DeleteItem(Guictrlgethandle($List1), $selecteditem)
     
     
     
     
    
    ;$selecteditem = _GUICtrlListBox_GetSelItems(GUICtrlRead($List1))
    ;$selecteditem1 = _GUICtrlListBox_DeleteString($List1,$selecteditem)
    ;MsgBox(64, "Debug", "Debug" & _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($List1))) returns TRUE but unable delete selected item.
    
    
    ;_ArrayDelete($List1, $selecteditem)
    ;$rt =StringReplace($List1, $selecteditem, "")
                             ;$stringreplace = StringReplace(GUICtrlRead($List1), $selecteditem, "Deyisdhi!")         ;isledi bu
                ;=>for debug
     if $selecteditem ="0" Then
         MsgBox(64,"No Line Selected!", "No Line Selected")
     Else
         MsgBox(64, "Debug", $delete  )
    MsgBox(64, "Debug", "Guictrlread($List1) is return valid selected:" & $selecteditem)
    $myparamgetcolumn = _GUICtrlListView_GetSelectedColumn($List1)
    MsgBox(64, "Get Columnselected",$myparamgetcolumn)
    EndIf
    
    ;RegDelete($goster,$d)
    ;GUICtrlSetData($List1, _GUICtrlListView_DeleteItemsSelected($trueselected))
    ;GUICtrlSetData($List1, "11111111")
    
    
    
    
    ;$selecteditem = _GUICtrlListBox_GetSelItems($List1)
    ;
    ;_GUICtrlListBox_ClickItem($List1, $selecteditem)
    
    ;DllCall("kernel32.dll", "ptr", "ExitProcess")
    
    
    EndSwitch
WEnd
Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

Yes I realize it too:) Here is result script it works fine.

Thanks to all whoever help me in this:

#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#NoTrayIcon
#comments-start

This script is show to you which entries you have on your win OS startup,and delete it from autostart.
Pliz before execute this script backup your regedit.
for delete entries from regedit you need administrative privelegies.
mY gREAT Thanks to PsalTyDs,Mat,Mobius
                       /Sh3llC043r
                       REALISED IN WONDERFULL AUTOITSCRIPT LANGUAGE
MODIFY AND USE IT FOR NEED YOURSELF.
sorry for awfull english
10.12.2k9



#ce

#Region ### START Koda GUI section ### Form=Form1.kxf\Form1.kxf
$Form1_1 = GUICreate("Show me what in my AutoStArt", 998, 551, 203, 109)
$goster ="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run "
$List1 = GUICtrlCreateListView("Regedit KEY" &"|" & "Name" & "|" & "Entry", 16, 24, 969, 409) ;


$Button1 = GUICtrlCreateButton("SCAN STARTUP", 72, 464, 105, 33, 0)
$Button2 = GUICtrlCreateButton("DELETE SEL..ENTRY ", 824, 464, 113, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$i ="|"
$a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
        _GUICtrlListView_DeleteAllItems($List1)
    for $i =1 to 20
                $a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)
                $b = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $a)

                if $a = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i) Then
                    $c = StringReplace($a, "Дополнительные данные отсутствуют.", "")
                    $d = StringReplace($c, @CRLF, "")
                    if $d ="" Then
                    GUICtrlCreateListViewItem("|" &  $d & "|" & $b, $List1)
                    Else              ;else never exist :)

    GUICtrlCreateListViewItem($goster & "|" &  $d & "|" & $b, $List1)



    EndIf

EndIf




                                      ;






Next
Case $Button2
     $deleteItem = _GUICtrlListView_GetSelectedIndices(GUICtrlRead($List1))
     $selecteditem = GUICtrlRead($List1)


     if $selecteditem ="0" Then
         MsgBox(64,"No Line Selected!", "No Line Selected")
     Else

    ;MsgBox(64, "Debug", "Guictrlread($List1) is return valid selected:" & $selecteditem)   ; i use it for debug

     $op=_GUICtrlListView_GetSelectedIndices($List1)

    $HotItem = $op
    local $HotItem1 = _GUICtrlListView_GetItemText(GUICtrlGetHandle($List1),$op,1)   ;Yeesssssssssssss i found it.
    ;$HotItem1 = _GUICtrlListView_GetItemText($List1,$op,1)   ;in here 0 is NAME columns    zapas ucundur.
    if @UserName = IsAdmin() Then
        MsgBox(64, "No Enough Privelegies!", "You have no Administrative Privelegies For delete=> " & $HotItem1 & "<= from regedit")
    Else

    RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$HotItem1)
    MsgBox(64, "Removed Successfully From Regedit   ",$HotItem1 & "<=Successfully Removed From Regedit!")
EndIf




    ;MsgBox(64, "HOT ITEM",$HotItem1 )        ; i use it for debug
    EndIf




    EndSwitch
WEnd
[size="5"] [/size]
Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

I realize I am several months late and it's a bit off topic, but @Sh3llC043r: What about all of the other registry keys that contain startup programs?

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\load

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify

Those are just a few off the top of my head, I'm sure theres more...

[size="1"][font="Lucida Console"]My ScriptsTrue multi-threaded ping[/font][/size]

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...