Jump to content

Setting Listview item index


 Share

Recommended Posts

searched alot in forum and in help file and there is no function to set the index of an already existing listview item did i miss anything?

is there something like _GuiCtrlListview_SetItemIndex

can anyone help?

thanks

look at _GUICtrlListView_GetItemTextArray() and _GUICtrlListView_SetItemText()

you will have to get the list of items, and then set item texts as needed in the order you want them. I've done something like this for a move up/down function within a listview in the past

[u]You can download my projects at:[/u] Pulsar Software
Link to comment
Share on other sites

  • Moderators

yehia,

Why are you dismissing maqleod's suggestion? How are you getting the data to populate your ListView - would it already be in array form perhaps? I have used something very similar to maqleod's idea to manipulate ListViews with many more than 27 items which are stored in an array. Here is an code snippet to move an item up the ListView by moving its position in the array and then rewriting the ListView itself:

Func List_Item_Up(ByRef $aList_Array, $hList, $hStart_ID)
; $hStart_ID is dummy control cretaed to enumerate ListView item ControlIDs

If $aList_Array[0] < 2 Then Return

; Get value of listview selection via handle count
$iList_Index = GUICtrlRead($hList) - $hStart_ID
; If already at top or no selection or out of range
If $iList_Index < 2 Or $iList_Index > $aList_Array[0] Then Return

; Swap array elements
_ArraySwap($aList_Array[$iList_Index],  $aList_Array[$iList_Index - 1])

; Rewrite list items
For $i = 1 To $aList_Array[0]
    GUICtrlSetData($hStart_ID + $i, $aList_Array[$i])
Next

; Unselect all items to force selection before next action
_GUICtrlListView_SetItemSelected ($hList, -1, False)

EndFunc

Of course, the visual penalty of the change in contents is only noticeable for the 2 items involved - all the others remain stable.

I have also rewritten ListViews where many items change - here I have just used GUICtrlSetState($hList_View, $GUI_HIDE/SHOW) to hide the ListView for the short time it takes to rewrite. Yes, you can see that something is happening, but the delay is minimal - and I am talking of over 200 items with multiple subitems.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

yehia,

Are you saying that the ListView you are trying to manipulate is in a non-AutoIt application?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Are you looking for _GUICtrlListView_SetItemSelected() ?

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