Jump to content

unordered listview


Recommended Posts

Listview automatically displays things in sorted order. Is there a way to get it to show things in the order that they're added? If not then is there something similar that can do it?

I tried putting a 0 in as the last parameter to GuiCtrlCreateList, and it seemed to work, but the problem is that the slider on the side is disabled, so when it gets full no new information is added. Also, if it sees something that already exists in the listview, it doesn't add it it just highlights it.

What I'm trying to do is create a status box.

Link to comment
Share on other sites

  • Moderators

Phenom,

Listview automatically displays things in sorted order

Oh no it does not! You have to use the $LVS_SORTASCENDING or $LVS_SORTDESCENDING styles to get a ListView to sort.

Take a look at this - is is sorted for you? It certainly is not for me! :mellow:

#include <GUIConstantsEx.au3>

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

$hLV = GUICtrlCreateListView("Header", 10, 10, 400, 450)

For $i = 1 To 20
    GUICtrlCreateListViewItem(Chr(Random(65, 90, 1)), $hLV)
Next

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

If you add the styles I mentioned above, it will display sorted data - but remember that you will have to also re-add the default styles if you wish to retain them. :P

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

This one does.

#include <GUIConstantsEx.au3>

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

$hLV = GUICtrlCreateList("",10, 10, 400, 450)

For $i = 1 To 20
    GUICtrlSetData($hLV, Chr(Random(65, 90, 1)))
Next
GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

What's the difference between a List and a ListView? How can I get your code to automatically scroll the window when more data is added to the end?

Link to comment
Share on other sites

  • Moderators

Phenom,

There are BIG differences between a List and a ListView. A List has only one element per line, no headers and cannot be sorted dynamically - all of which a ListView can do. You need to be careful not to mix the two - they are very different beasts. :party:

Your List will sort automatically because the default styles for a List include $LBS_SORT - you need to redeclare the styles without it to prevent sorting:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

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

$hLV = GUICtrlCreateList("",10, 10, 400, 450, BitOr($WS_BORDER, $WS_VSCROLL))

For $i = 1 To 20
    GUICtrlSetData($hLV, Chr(Random(65, 90, 1)))
Next
GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

As to scrolling to the last entry in a ListView, you need to use the GUIListView UDF like this:

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

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

$hLV = GUICtrlCreateListView("Header", 10, 10, 400, 250)

GUISetState()

For $i = 1 To 20
    GUICtrlCreateListViewItem(Chr(Random(65, 90, 1)), $hLV)
    _GUICtrlListView_EnsureVisible($hLV, $i - 1)
    Sleep(500) ; Just so you can see it happening before your very eyes!
Next

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

There are loads of very interesting functions in the GUIListView UDF, but many of them require you to create the ListView with the UDF functions rather than the built-in commands. However, as you can see here, some work either way. :P

All clear now? :mellow:

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

The code for the List works better now but it's still not adding duplicate entries. Is there a way to fix that?

For the second parameter of _GUICtrlListView_EnsureVisible(), if you're not keeping track of it with a variable is there some other thing you can put in there to make it work?

Also, don't you think it's strange that the syntax for the parameters of these two functions are opposite?

Link to comment
Share on other sites

  • Moderators

Phenom,

If you want duplicate entries in a list, you need to create a string of the entries and then set them all at once. Otherwise you do not get duplicates - as you discovered: :P

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

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

$hLV = GUICtrlCreateList("",10, 10, 400, 450, BitOr($WS_BORDER, $WS_VSCROLL))

$sData = ""
For $i = 1 To 20
    $sData &= Chr(Random(65, 67, 1)) & "|" ; Do not forget to add the delimiter!
Next

GUICtrlSetData($hLV, $sData) ; Set them all at once

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

don't you think it's strange that the syntax for the parameters of these two functions are opposite?

Do you mean these:

GUICtrlCreateListViewItem(Chr(Random(65, 90, 1)), $hLV)
_GUICtrlListView_EnsureVisible($hLV, $i - 1)

Well, the first is a built-in AutoIt function while the second is from the GUIListView UDF, so you had best ask the author of the UDF. I have no problem with them as they are - I usually look up the syntax of any but the most common commands to make sure I get the parameters correct.

Is your code working as you wish now? :mellow:

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

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