Jump to content

ListView extended styles


Recommended Posts

Hi everybody :)
I often read in the Forum that Listview extended styles should be applied using the _GUICtrlListView_SetExtendedListViewStyle UDF command. For example Melba23 wrote it in this link, and he adds that it should be done "whether the ListView is a native or UDF created control"

My question is : why the example below doesn't follow that rule ?

1) With $LVS_EX_CHECKBOXES applied within the GUICtrlCreateListView() command, then the checkbox in 1st row is automatically checked during 3 seconds, before unchecking itself. This looks correct :

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

GUICreate("Test - good result")

$idListView = GUICtrlCreateListView("Column 1", 25, 25, 350, 350, -1, $LVS_EX_CHECKBOXES)

GUISetState(@SW_SHOW)

$idItem1 = GUICtrlCreateListViewItem("12345", $idListView)
$idItem2 = GUICtrlCreateListViewItem("67890", $idListView)

GUICtrlSetState($idItem1, $GUI_CHECKED) ; works
Sleep(3000)
GUICtrlSetState($idItem1, $GUI_UNCHECKED)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

GUIDelete()

2) With $LVS_EX_CHECKBOXES applied within _GUICtrlListView_SetExtendedListViewStyle() then the 1st row isn't  checked when you run the script, which is incorrect :

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

GUICreate("Test - bad result")

$idListView = GUICtrlCreateListView("Column 1", 25, 25, 350, 350)
_GUICtrlListView_SetExtendedListViewStyle($idListView, $LVS_EX_CHECKBOXES)

GUISetState(@SW_SHOW)

$idItem1 = GUICtrlCreateListViewItem("12345", $idListView)
$idItem2 = GUICtrlCreateListViewItem("67890", $idListView)

GUICtrlSetState($idItem1, $GUI_CHECKED) ; doesn't work
Sleep(3000)
GUICtrlSetState($idItem1, $GUI_UNCHECKED)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

GUIDelete()

Any idea that could explain this behavior ?

Link to comment
Share on other sites

  • Moderators

pixelsearch,

It appears that the GUICtrlSetState does not work after using _GUICtrlListView_SetExtendedListViewStyle - you need to use _GUICtrlListView_SetItemChecked, as this example script shows:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <Constants.au3>
#include <WinAPI.au3>

GUICreate("Test")

$idListView = GUICtrlCreateListView("Column 1", 25, 25, 350, 350);, -1, $LVS_EX_CHECKBOXES)

_GUICtrlListView_SetExtendedListViewStyle($idListView, $LVS_EX_CHECKBOXES)

GUISetState(@SW_SHOW)

$idItem1 = GUICtrlCreateListViewItem("12345", $idListView)
$idItem2 = GUICtrlCreateListViewItem("67890", $idListView)

MsgBox($MB_SYSTEMMODAL, "Checking Method", "GUICtrlSetState")

GUICtrlSetState($idItem1, $GUI_CHECKED)
Sleep(1000)
GUICtrlSetState($idItem1, $GUI_UNCHECKED)

MsgBox($MB_SYSTEMMODAL, "Checking Method", "_GUICtrlListView_SetItemChecked")

_GUICtrlListView_SetItemChecked($idListView, 0, True)
Sleep(1000)
_GUICtrlListView_SetItemChecked($idListView, 0, False)


While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

GUIDelete()

Quite why this happens I have no idea, but experience has shown that once you start playing with the library UDF functions it is best to stick with them. My guess would be that using the UDF functions can mean that the details of the control held internally by AutoIt are not necessarily updated when UDF functions are used and so the native GUI* functions may not have the correct data on which to work. In this case the "internal-to-AutoIt" style does not get set to $LVS_EX_CHECKBOXES and so the GUISetState fails when you try to check the box - this would also explain why there is no error set (I checked to see) as the command is considered valid but the parameter ignored.

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

Thanks Melba23 for the explanations :)
I'll share soon some results of other tests concerning LV extended styles. It's a real headache because of the same values listed below. God only knows how many times you commented about this...

WS_EX_DLGMODALFRAME   0x00000001   LVS_EX_GRIDLINES
-                     0x00000002   LVS_EX_SUBITEMIMAGES
WS_EX_NOPARENTNOTIFY  0x00000004   LVS_EX_CHECKBOXES
WS_EX_TOPMOST         0x00000008   LVS_EX_TRACKSELECT
WS_EX_ACCEPTFILES     0x00000010   LVS_EX_HEADERDRAGDROP
WS_EX_TRANSPARENT     0x00000020   LVS_EX_FULLROWSELECT
WS_EX_MDICHILD        0x00000040   LVS_EX_ONECLICKACTIVATE
WS_EX_TOOLWINDOW      0x00000080   LVS_EX_TWOCLICKACTIVATE
WS_EX_WINDOWEDGE      0x00000100   LVS_EX_FLATSB
WS_EX_CLIENTEDGE      0x00000200   LVS_EX_REGIONAL
WS_EX_CONTEXTHELP     0x00000400   LVS_EX_INFOTIP
-                     0x00000800   LVS_EX_UNDERLINEHOT
WS_EX_RIGHT           0x00001000   LVS_EX_UNDERLINECOLD
WS_EX_RTLREADING      0x00002000   LVS_EX_MULTIWORKAREAS
WS_EX_LEFTSCROLLBAR   0x00004000   LVS_EX_LABELTIP
-                     0x00008000   LVS_EX_BORDERSELECT
WS_EX_CONTROLPARENT   0x00010000   LVS_EX_DOUBLEBUFFER
WS_EX_STATICEDGE      0x00020000   LVS_EX_HIDELABELS
WS_EX_APPWINDOW       0x00040000   LVS_EX_SINGLEROW (unused)
WS_EX_LAYERED         0x00080000   LVS_EX_SNAPTOGRID
WS_EX_NOINHERITLAYOUT 0x00100000   LVS_EX_SIMPLESELECT
WS_EX_LAYOUTRTL       0x00400000   -
WS_EX_COMPOSITED      0x02000000   -
WS_EX_NOACTIVATE      0x08000000   LVS_EX_AUTOCHECKSELECT (Vista +)

 

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