JeromeB Posted May 28, 2013 Posted May 28, 2013 (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 May 28, 2013 by JeromeB
BrewManNH Posted May 28, 2013 Posted May 28, 2013 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 GudeHow 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
JeromeB Posted May 28, 2013 Author Posted May 28, 2013 And with the _GUICtrlListView_Create i noticed that i cant set back then a color :s
Moderators Melba23 Posted May 28, 2013 Moderators Posted May 28, 2013 JeromeB, You can do it using my GUIListViewEx UDF - like this: expandcollapse popup#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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JeromeB Posted May 28, 2013 Author Posted May 28, 2013 (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 May 28, 2013 by JeromeB
Moderators Melba23 Posted May 28, 2013 Moderators Posted May 28, 2013 JeromeB, Some people are never satisfied! 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JeromeB Posted May 28, 2013 Author Posted May 28, 2013 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 ?
Moderators Melba23 Posted May 28, 2013 Moderators Posted May 28, 2013 (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. M23Edit: 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? Edited May 28, 2013 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Moderators Melba23 Posted May 28, 2013 Moderators Posted May 28, 2013 JeromeB,Here you go - you will need the new version of the UDF to make it work correctly: expandcollapse popup#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) EndFuncGood 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? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now