Jump to content

Moving or resizing a ListView created with _GUICtrlListView_Create


Go to solution Solved by mikell,

Recommended Posts

How does one move or resize a ListView control that was created using _GUICtrlListView_Create?

This doesn't work:

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

; Create GUI with a _GUICtrlListView control
Global $hGUI = GUICreate("_GUICtrlListView", 700, 500, -1, -1, $WS_OVERLAPPEDWINDOW)
Global $hListView = _GUICtrlListView_Create($hGUI, "", 100, 100, 500, 300, BitOR($LVS_ICON, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
GUISetState(@SW_SHOW, $hGUI)

MsgBox(0, "Note intial ListView position (centered on the GUI)", "Press OK to try to move ListView to bottom right corner of the GUI window.")

GUICtrlSetPos($hListView, 200, 200)
MsgBox(0, "GUICtrlSetPos($hListView, 100, 100)", "Why didn't it move?")

GUICtrlSetPos($hListView, 100, 100, 600, 400)
MsgBox(0, "GUICtrlSetPos($hListView, 100, 100, 600, 400)", "We can't change the size either.")

; Loop until the user exits the GUI
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

GUIDelete()

 

Link to post
Share on other sites
  • Solution

GuiCtrlSetPos works using IDs not handles

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

; Create GUI with a _GUICtrlListView control
Global $hGUI = GUICreate("_GUICtrlListView", 700, 500, -1, -1, $WS_OVERLAPPEDWINDOW)
Global $hListView = _GUICtrlListView_Create($hGUI, "", 100, 100, 500, 300, BitOR($LVS_ICON, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
GUISetState(@SW_SHOW, $hGUI)

MsgBox(0, "Note intial ListView position (centered on the GUI)", "Press OK to try to move ListView to bottom right corner of the GUI window.")

WinMove($hListView, "", 200, 200) ; or ControlMove($hListView, "", "", 200, 200)
Sleep(1000)
WinMove($hListView, "", 100, 100, 600, 400)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

GUIDelete()

 

Edited by mikell
typo
Link to post
Share on other sites

@mikell Thanks! I tried both WinMove and ControlMove as you suggested and both worked perfectly well to move and/or resize the listview.

Obviously I overlooked the important difference between a Control ID and a Handle, and that the built-in GUICtrlCreateListView function returns the identifier (controlID) of the new control, whereas the _GUICtrlListView_Create returns the handle to the ListView control.

That's a distinction I will pay very careful attention to from now on. :doh:

And logically that would mean then that any UDF-based controls like this are incompatible with the GUI Control update functions.

Thanks for the education.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...