Sign in to follow this  
Followers 0
maniootek

GUICtrlCreateListViewItem add new item "on top" instead of "on botton"

12 posts in this topic

Hi.

Any chance that function GUICtrlCreateListViewItem() create new entry to ListView but any new item will go on the top of the list?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hey,

there's a style in ListviewConstants.au3 called $LVS_SORTDESCENDING (0x0020).

This should be exactly what you need.

Edited by Radiance

Share this post


Link to post
Share on other sites

any chance to change it in script without modify any au3 file?

Share this post


Link to post
Share on other sites

Radiance,

That style just sorts the ListView items, nothing to do with insertion order. ;)

maniootek,

If you use my GUIListViewEx UDF - look in my sig for the link you can do it pretty easily: :)

#include <GUIConstantsEx.au3>
#include "GUIListViewEx.au3"

$iCount = 4

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView("Col 1|Col 2", 10, 10, 250, 200)
For $i = 0 To $iCount
    GUICtrlCreateListViewItem("0-" & $i & "|1-" & $i, $cLV)
Next

$cInsert = GUICtrlCreateButton("Insert", 10, 450, 80, 30)

GUISetState()

; Read ListView content
$aList = _GUIListViewEx_ReadToArray($cLV)
; Initialise ListView
$iLV_Index = _GUIListViewEx_Init($cLV, $aList)
; Register ListView messages
_GUIListViewEx_MsgRegister()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cInsert
            ; Click on top item
            _GUICtrlListView_ClickItem($cLV, 0)
            ; Just to distinguish the new items
            $iCount += 1
            ; Indert below selected item
            _GUIListViewEx_Insert("0-" & $iCount & "|1-" & $iCount)
            ; And move up one place
            _GUIListViewEx_Up()
            ; Cancel the automatic selection of the new item
            _GUICtrlListView_SetItemSelected($cLV, 0, False)
    EndSwitch

WEnd
It could get a bit flicker if you have a lot of rows, but that is a price you will have to pay. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

From what I know you can't manipulate GUI controls from outside a running script.

Share this post


Link to post
Share on other sites

Radiance,

That style just sorts the ListView items, nothing to do with insertion order. ;)

 

When I use the style every new item goes straight to the top of the list.

$GUI = GUICreate("Test", 250, 200)
$List = GUICtrlCreateListView("                ",0 ,0 ,250, 200, 0x0020)
GUISetState()

Sleep(1000)

$Red = GUICtrlCreateListViewItem("Text", $List)
GUICtrlSetbkColor(-1, 0xFFBEBE)

Sleep(1000)

$Green = GUICtrlCreateListViewItem("Text", $List)
GUICtrlSetbkColor(-1, 0xBEFFBE)

Sleep(1000)

$Yellow = GUICtrlCreateListViewItem("Text", $List)
GUICtrlSetbkColor(-1, 0xF7F7B0)

Sleep(2000)

Care to explain?

Share this post


Link to post
Share on other sites

When I use the style every new item goes straight to the top of the list.

$GUI = GUICreate("Test", 250, 200)
$List = GUICtrlCreateListView("                ",0 ,0 ,250, 200, 0x0020)
GUISetState()

Sleep(1000)

$Red = GUICtrlCreateListViewItem("Text", $List)
GUICtrlSetbkColor(-1, 0xFFBEBE)

Sleep(1000)

$Green = GUICtrlCreateListViewItem("Text", $List)
GUICtrlSetbkColor(-1, 0xBEFFBE)

Sleep(1000)

$Yellow = GUICtrlCreateListViewItem("Text", $List)
GUICtrlSetbkColor(-1, 0xF7F7B0)

Sleep(2000)

Care to explain?

 

works! thanks!

I just also noticed that this option is described under this manual:

https://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateListView.htm

in example you can see line:

    Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING)

so you can just unquote that option $LVS_SORTDESCENDING to get this:

    Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150, $LVS_SORTDESCENDING)

Share this post


Link to post
Share on other sites

Radiance,

 

Care to explain?

Delighted. :)

You are inserting the same text each time so there is no "alphabetical order" to sort. AutoIt then looks for the item parameter value - which for native-created items is the ControlID. As these increase in value each time you create an item, the latest (and highest value) item goes to the top. But if you have real differences in the text you add, the AutoIt sorts on that - as you can see here:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>

$GUI = GUICreate("Test", 250, 200)
$List = GUICtrlCreateListView("                ",0 ,0 ,250, 200, $LVS_SORTDESCENDING)
GUISetState()

Sleep(1000)

GUICtrlCreateListViewItem("Text Z", $List)

Sleep(1000)

GUICtrlCreateListViewItem("Text A", $List)

Sleep(1000)

GUICtrlCreateListViewItem("Text Y", $List)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

maniootek,

I am afraid the answer is not the one you have marked - please read my post immediately above. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

I have noticed that ListView is sorted correctly now (SORTDESCENDING) but index of items are not changed.

Example: I have three items in the ListView and the item on the top has index "1" when the other on the middle has "2" and bottom "3"

but item with index "1" is displayed on the bottom which is not correct for me

Share this post


Link to post
Share on other sites

maniootek,

Please post the code you use - merely stating (not very clearly) the end result is not a lot of help. ;)

Basically, Radiance's suggestion is NOT the answer to inserting at the top unless you keep adding items that are always alphabetically higher valued than everything already in place. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

All clear? :)

 

 

Yes, thanks! I'm using this and basically never had a case (yet) where this would have stood out.

Apologies for the wrong answer, I guess I have to rewrite some scripts now.

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