Sign in to follow this  
Followers 0
JeromeB

ListView item add on top

9 posts in this topic

#1 ·  Posted (edited)

Hey guys,

I got a listview created like that ; 

$List1 = GUICtrlCreateListView(" ", 8, 40, 369, 292, $LVS_NOCOLUMNHEADER )

 

And i add item with GUICtrlCreateListViewItem (because i use GUICtrlSetBkColor just after)

Do you know how i can always add my item on top of other (descending the other).

Something like, instead of : 

1< First item

2

3

4 < Last item

I get

4 < Last item

3

2

1< First item

 

thx :)

Edited by JeromeB

Share this post


Link to post
Share on other sites



You'd have to rebuild the listview, with your items in the correct order, prior to adding them each time, because with the native function (GUICtrlCreateListViewItem) there's no way to specify which index to add the item at.


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

Share this post


Link to post
Share on other sites

And with the _GUICtrlListView_Create

i noticed that i cant set back then a color :s

Share this post


Link to post
Share on other sites

JeromeB,

You can do it using my GUIListViewEx UDF - like this: ;)

#include <GUIConstantsEx.au3>

#include <GuiListViewEx.au3>

Global $iCount = 1

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

$cLV = GUICtrlCreateListView(" ", 10, 10, 480, 300, $LVS_NOCOLUMNHEADER)
_GUICtrlListView_SetColumnWidth($cLV, 0, 450)
$cButton = GUICtrlCreateButton("Add", 10, 450, 80, 30)

GUISetState()

; Read the ListView and intialise the UDF
$aLV = _GUIListViewEx_ReadToArray($cLV)
_GUIListViewEx_Init($cLV, $aLV)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            ; Create text
            $sText = "Item " & $iCount
            $iCount += 1
            ; Add item to ListView
            _GUIListViewEx_Insert($sText)
            ; Get index of added item
            $iIndex = _GUICtrlListView_FindText($cLV, $sText)
            ; Select it
            _GUICtrlListView_ClickItem($cLV, $iIndex)
            ; Move it to the top
            For $i = 0 To $iIndex
                _GUIListViewEx_Up()
            Next
    EndSwitch

WEnd

Does that work for you? :)

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

#5 ·  Posted (edited)

Awesome.

but two questions :

1 : how can i setup back a color for an item (i'm using different color every time i add an item)

i did it with 

 

GUICtrlCreateListViewItem( "1", $List1)
GUICtrlSetBkColor(-1, 0xFFBC00)
 
But this is not working anymore :s
 
 
 2: Is there is a way to do not select the last item every time ?
Edited by JeromeB

Share this post


Link to post
Share on other sites

JeromeB,

Some people are never satisfied! :P

I will see what I can do. :)

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

hahahah :)

thank ou for your time.

Btw, just like that, does it will still work fine (i mean fast enough) if i got like 10 000 items in my listview and i move back the 10 001 on top ?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

JeromeB,

 

Trying to solve your problem has exposed a bug in my UDF.  I will have to deal with that first - so please be patient. :)

 

And I have changed the code to insert the item - it will always be very fast as it only moves up 1 place now. ;)

 

M23

Edit: Although are you serious about 10,000 items? Any ListView with that many entries is going to be pretty slow! Why on earth do you need so many? :huh:

Edited by Melba23

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

JeromeB,

Here you go - you will need the new version of the UDF to make it work correctly: :)

#include <GUIConstantsEx.au3>

#include <GuiListViewEx.au3>

Global $aItem_Colour[1] = [0]

Global $aColours[3] = [0xFFCCCC, 0xCCFFCC, 0xCCCCFF] ; Just to have some colours available

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

$cLV = GUICtrlCreateListView(" ", 10, 10, 480, 300, $LVS_NOCOLUMNHEADER)
_GUICtrlListView_SetColumnWidth($cLV, 0, 450)
$cButton = GUICtrlCreateButton("Add", 10, 450, 80, 30)

GUISetState()

; Read the ListView and intialise the UDF
$aLV = _GUIListViewEx_ReadToArray($cLV)
_GUIListViewEx_Init($cLV, $aLV)

For $i = 1 To 10
    _AddItem("Item " & $aItem_Colour[0] + 1, $aColours[Random(0, 2, 1)]) 
Next

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            _AddItem("Item " & $aItem_Colour[0] + 1, $aColours[Random(0, 2, 1)])
    EndSwitch

WEnd


Func _AddItem($sText, $iColour)

    ; Increase size of array
    $aItem_Colour[0] += 1
    ReDim $aItem_Colour[$aItem_Colour[0] + 1]

    ; Store colour
    $aItem_Colour[$aItem_Colour[0]] = $iColour

    ; Select top item
    _GUICtrlListView_SetItemSelected($cLV, 0, True)
    ; Add item to ListView
    _GUIListViewEx_Insert($sText)
    ; Move it to the top
    _GUIListViewEx_Up()
    ; Unselect it
    ; Get CID of top item
    $cTopItem = GUICtrlRead($cLV)
    ; Unselect it
    _GUICtrlListView_SetItemSelected($cLV, 0, False)

    ; Recolour the items
    _GUICtrlListView_BeginUpdate($cLV)
    For $i = 0 To $aItem_Colour[0] - 1
        GUICtrlSetBkColor($cTopItem + $i, $aItem_Colour[$aItem_Colour[0] - $i])
    Next
    _GUICtrlListView_EndUpdate($cLV)

EndFunc
Good enough?  And I would still like to know why you need so many items in the ListView! How can anyone use it with so many? :huh:

 

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

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