Jump to content

Recommended Posts

need some help, i have a listview. i want display the last item only and delete the previous item(s). for instance if i have 4 items i will delete item 1, 2,3  only the 4 item will be visible on the listview, the code below seems to work partly  thanks ahead

$aListViews = GUICtrlCreateListView("| UCS Subnet/ 28||", 76, 8, 361, 473, -1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)) ;56



            if $Selection1 = True Then
                  $noip = $sValueread
              ; load row in listview


                For $j = 1 To  $noip
                    GUICtrlCreateListViewItem('Static|SREI' & StringFormat('%05d', $checknum) & 'RE0' & $j & '|' & $ip2[UBound($ip2) - 1] + 15 + $j, $aListViews)
                    ;GUICtrlCreateListViewItem('Static|Register ' & $j & '|' & $ip2[UBound($ip2) - 1] + 15 + $j, $alistviews)
                    ConsoleWrite($j &"$noip"&@CRLF)
Next
ConsoleWrite(@CRLF)

For $j=1 To  $noip-1
                 _GUICtrlListView_DeleteItem($aListviews,  $j)
                  ; _GUICtrlListView_DeleteItemsSelected($aListviews)

Next

the attach example  the max item was 2, it should have deleted item 1, only item 2 should have been visible on the listview

listviweCapture.JPG

Link to comment
Share on other sites

If you will show me your complete script I will test it, coz im getting lots of syntax error and Im quite lazy to re-construct it :D

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

The code is huge and connected to a database, I just want the snippet here;s an example the help file. as you can see I try to modify it, however  it does not give me the result I was expecting.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    GUICreate("ListView Item Deletion", 400, 500)
    Local $idListview = GUICtrlCreateListView("Col 1               |Col 2      |Col 3      ", 10, 10, 380, 480, $LVS_SHOWSELALWAYS)
    GUISetState(@SW_SHOW)

    For $i = 0 To 9
        GUICtrlCreateListViewItem("Native Item " & $i & "|Item " & "-1|Item "  & "-2", $idListview)
    Next
    ;For $i = 10 To 20
     ;   _GUICtrlListView_AddItem($idListview, "UDF Item " & $i, -1, 1000 + $i)
      ;  _GUICtrlListView_AddSubItem($idListview, $i, "Item " & $i & "-1", 1)
       ; _GUICtrlListView_AddSubItem($idListview, $i, "Item " & $i & "-2", 2)
    ;Next

    ; Pass the controlID of a native-created ListView to delete both native- and UDF-created Items
    ;MsgBox($MB_SYSTEMMODAL, "Delete item", "Deleting UDF-created Item 12")
    ;_GUICtrlListView_DeleteItem($idListview, 12)

    MsgBox($MB_SYSTEMMODAL, "Single", "Deleting native-created Item 9")

    For $i = 0 To 8

    _GUICtrlListView_DeleteItem($idListview, $i)
     Next


    ; Loop until the user exits
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete()
EndFunc   ;==>Example

 

Edited by antonioj84
error
Link to comment
Share on other sites

5 minutes ago, Tekk said:

To delete a range of items you need to do so in reverse order or else when you delete item one, item two becomes the new item one and so on.
 

For $i = 8 To 0 Step -1
    _GUICtrlListView_DeleteItem($idListview, $i)
Next

 

it works,it delete now, just need to figure out   how to not have the last item deleted 

Link to comment
Share on other sites

For $i = _GUICtrlListView_GetItemCount($idListview) - 2 To 0 Step - 1
    _GUICtrlListView_DeleteItem($idListview, $i)
Next

or 

Local $nItems = _GUICtrlListView_GetItemCount($idListview)

_DeleteRange($idListview, 0, $nItems - 1)

Func _DeleteRange($idListview, $nStart, $nCount)
    _GUICtrlListView_BeginUpdate($idListview)

    While $nCount > 0
        _GUICtrlListView_DeleteItem($idListview, $nStart)
        $nCount -= 1
    WEnd

    _GUICtrlListView_EndUpdate($idListview)
EndFunc

 

Link to comment
Share on other sites

I dont really know your condition to delete LV items so here's what I've got.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    $GUI = GUICreate("ListView Item Deletion", 400, 500)
    $INPUT = GUICtrlCreateInput("", 10, 10, 100, 20)
    $button = GUICtrlCreateButton("Delete", 115, 10, 50, 20)
    $button1 = GUICtrlCreateButton("Load", 175, 10, 50, 20)
    Local $idListview = GUICtrlCreateListView("Col 1               |Col 2      |Col 3      ", 10, 75, 380, 480, $LVS_SHOWSELALWAYS)
    GUISetState(@SW_SHOW)

    For $i = 0 To 9
        $lv = GUICtrlCreateListViewItem("Native Item " & $i & "|Item " & "-1|Item " & "-2", $idListview)
    Next
    ;For $i = 10 To 20
    ;   _GUICtrlListView_AddItem($idListview, "UDF Item " & $i, -1, 1000 + $i)
    ;  _GUICtrlListView_AddSubItem($idListview, $i, "Item " & $i & "-1", 1)
    ; _GUICtrlListView_AddSubItem($idListview, $i, "Item " & $i & "-2", 2)
    ;Next

    ; Pass the controlID of a native-created ListView to delete both native- and UDF-created Items
    ;MsgBox($MB_SYSTEMMODAL, "Delete item", "Deleting UDF-created Item 12")
    ;_GUICtrlListView_DeleteItem($idListview, 12)

    ; Loop until the user exits
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $button
                $read = GUICtrlRead($INPUT)
                _GUICtrlListView_DeleteItem($idListview, $read)
            Case $button1
                _GUICtrlListView_DeleteAllItems($idListview)
                For $i = 0 To 9
                    $lv = GUICtrlCreateListViewItem("Native Item " & $i & "|Item " & "-1|Item " & "-2", $idListview)
                Next
        EndSwitch
    WEnd


    ; Delete the previous GUI and all controls.
    GUIDelete()
EndFunc   ;==>Example

 

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

39 minutes ago, Tekk said:
For $i = _GUICtrlListView_GetItemCount($idListview) - 2 To 0 Step - 1
    _GUICtrlListView_DeleteItem($idListview, $i)
Next

or 

Local $nItems = _GUICtrlListView_GetItemCount($idListview)

_DeleteRange($idListview, 0, $nItems - 1)

Func _DeleteRange($idListview, $nStart, $nCount)
    _GUICtrlListView_BeginUpdate($idListview)

    While $nCount > 0
        _GUICtrlListView_DeleteItem($idListview, $nStart)
        $nCount -= 1
    WEnd

    _GUICtrlListView_EndUpdate($idListview)
EndFunc

 

works both like a charm, kudo much appreciated

Link to comment
Share on other sites

14 minutes ago, 232showtime said:

I dont really know your condition to delete LV items so here's what I've got.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    $GUI = GUICreate("ListView Item Deletion", 400, 500)
    $INPUT = GUICtrlCreateInput("", 10, 10, 100, 20)
    $button = GUICtrlCreateButton("Delete", 115, 10, 50, 20)
    $button1 = GUICtrlCreateButton("Load", 175, 10, 50, 20)
    Local $idListview = GUICtrlCreateListView("Col 1               |Col 2      |Col 3      ", 10, 75, 380, 480, $LVS_SHOWSELALWAYS)
    GUISetState(@SW_SHOW)

    For $i = 0 To 9
        $lv = GUICtrlCreateListViewItem("Native Item " & $i & "|Item " & "-1|Item " & "-2", $idListview)
    Next
    ;For $i = 10 To 20
    ;   _GUICtrlListView_AddItem($idListview, "UDF Item " & $i, -1, 1000 + $i)
    ;  _GUICtrlListView_AddSubItem($idListview, $i, "Item " & $i & "-1", 1)
    ; _GUICtrlListView_AddSubItem($idListview, $i, "Item " & $i & "-2", 2)
    ;Next

    ; Pass the controlID of a native-created ListView to delete both native- and UDF-created Items
    ;MsgBox($MB_SYSTEMMODAL, "Delete item", "Deleting UDF-created Item 12")
    ;_GUICtrlListView_DeleteItem($idListview, 12)

    ; Loop until the user exits
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $button
                $read = GUICtrlRead($INPUT)
                _GUICtrlListView_DeleteItem($idListview, $read)
            Case $button1
                _GUICtrlListView_DeleteAllItems($idListview)
                For $i = 0 To 9
                    $lv = GUICtrlCreateListViewItem("Native Item " & $i & "|Item " & "-1|Item " & "-2", $idListview)
                Next
        EndSwitch
    WEnd


    ; Delete the previous GUI and all controls.
    GUIDelete()
EndFunc   ;==>Example

 

ThANK you guys you are amazing

Link to comment
Share on other sites

or just read $i

 

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    GUICreate("ListView Item Deletion", 400, 500)
    Local $idListview = GUICtrlCreateListView("Col 1               |Col 2      |Col 3      ", 10, 10, 380, 480, $LVS_SHOWSELALWAYS)
    GUISetState(@SW_SHOW)

    For $i = 0 To 9
        GUICtrlCreateListViewItem("Native Item " & $i & "|Item " & "-1|Item " & "-2", $idListview)
    Next
    ;For $i = 10 To 20
    ;   _GUICtrlListView_AddItem($idListview, "UDF Item " & $i, -1, 1000 + $i)
    ;  _GUICtrlListView_AddSubItem($idListview, $i, "Item " & $i & "-1", 1)
    ; _GUICtrlListView_AddSubItem($idListview, $i, "Item " & $i & "-2", 2)
    ;Next

    ; Pass the controlID of a native-created ListView to delete both native- and UDF-created Items
    ;MsgBox($MB_SYSTEMMODAL, "Delete item", "Deleting UDF-created Item 12")
    ;_GUICtrlListView_DeleteItem($idListview, 12)

;~  MsgBox($MB_SYSTEMMODAL, "Single", "Deleting native-created Item 9")

    For $i = 0 To 8
        $read = GUICtrlRead($i)
        Sleep(100)
        _GUICtrlListView_DeleteItem($idListview, $read)
        ConsoleWrite(@error)


    Next


    ; Loop until the user exits
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete()
EndFunc   ;==>Example

 

 

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

Just now, 232showtime said:

or just read $i

 

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    GUICreate("ListView Item Deletion", 400, 500)
    Local $idListview = GUICtrlCreateListView("Col 1               |Col 2      |Col 3      ", 10, 10, 380, 480, $LVS_SHOWSELALWAYS)
    GUISetState(@SW_SHOW)

    For $i = 0 To 9
        GUICtrlCreateListViewItem("Native Item " & $i & "|Item " & "-1|Item " & "-2", $idListview)
    Next
    ;For $i = 10 To 20
    ;   _GUICtrlListView_AddItem($idListview, "UDF Item " & $i, -1, 1000 + $i)
    ;  _GUICtrlListView_AddSubItem($idListview, $i, "Item " & $i & "-1", 1)
    ; _GUICtrlListView_AddSubItem($idListview, $i, "Item " & $i & "-2", 2)
    ;Next

    ; Pass the controlID of a native-created ListView to delete both native- and UDF-created Items
    ;MsgBox($MB_SYSTEMMODAL, "Delete item", "Deleting UDF-created Item 12")
    ;_GUICtrlListView_DeleteItem($idListview, 12)

;~  MsgBox($MB_SYSTEMMODAL, "Single", "Deleting native-created Item 9")

    For $i = 0 To 8
        $read = GUICtrlRead($i)
        Sleep(100)
        _GUICtrlListView_DeleteItem($idListview, $read)
        ConsoleWrite(@error)


    Next


    ; Loop until the user exits
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete()
EndFunc   ;==>Example

 

so many ways we can skin a cat, I am keeping these snitppets

 

Link to comment
Share on other sites

Sorry, Guys I  can NOT figure this one out, the code work great however it will not display this line below, 

" GUICtrlCreateListViewItem('|Default Gateway >|' & $ip2[UBound($ip2) - 1] + 1, $aListViews)" 

$aListViews = GUICtrlCreateListView("| UCS Subnet/ 28||", 76, 8, 361, 473, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ;56
  GUICtrlCreateListViewItem('|Default Gateway >|' & $ip2[UBound($ip2) - 1] + 1, $aListViews)


                If $Selection1 = True Then
                    $noip = $sValueread
                    ; load row in listview


                    For $j = 0 To $noip


        GUICtrlCreateListViewItem('Static|SREI' & StringFormat('%05d', $Checknum) & 'RE0' & $j & '|' & $ip2[UBound($ip2) - 1] + 15 + $j, $aListViews)
        ;GUICtrlCreateListViewItem('Static|Register ' & $j & '|' & $ip2[UBound($ip2) - 1] + 15 + $j, $alistviews)
                        ConsoleWrite($j & "$noip" & @CRLF)
                    Next
                    ConsoleWrite(@CRLF)

                     ; $noip = $noip -1
                      Local $nItems = _GUICtrlListView_GetItemCount($aListviews)


                   _DeleteRange($aListviews, 0, $nItems -1)


                    ;For $j = _GUICtrlListView_GetItemCount($aListViews) - 2 To 0 Step -1
                    ;   _GUICtrlListView_DeleteItem($aListViews, $j)
                    ;Next


                EndIf

Func _DeleteRange($aListviews, $nStart, $nCount)
  _GUICtrlListView_BeginUpdate($aListviews)

    While $nCount > 0
        _GUICtrlListView_DeleteItem($aListviews, $nStart)
        $nCount -= 1
    WEnd

    _GUICtrlListView_EndUpdate($aListviews)
EndFunc






                For $j = $noprinter To 1 Step -1

                    If $j = 2 Then GUICtrlCreateListViewItem('Static|Front Printer ' & $j & '|' & $ip2[UBound($ip2) - 1] + 35, $aListViews)
                    If $j = 1 Then GUICtrlCreateListViewItem('Last Static|Back Printer ' & $j & '|' & $ip2[UBound($ip2) - 1] + 36, $aListViews)
                Next

 

I was expecting gateaway also to be displayed on the listview

 

 

 

listviewLastCapture.JPG

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

×
×
  • Create New...