Gui Listview questions Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Gui Listview questions

Post by Hellbent » 29 Nov 2023, 02:07

Hi, I have a questions related to the listview gui control.

What is the syntax to specify a particular window and listview control?

For example, how would I use the F1 hotkey to make changes to the 3rd listview on Gui2 in the code below?

Code: Select all


Loop, 5	{
	Gui, New, % "+hwndGui" A_Index
	Loop, 5	{
		Gui, Add, Listview, % "+hwndListview" A_Index
	}
	Gui, Show
}

F1::
	LV_ModifyCol( 2 , 200 )
	LV_Delete()
	LV_Add( "" , "Add" , "ControlType := ""Button""" , "options := """"" )
	return
For context, this is what I am trying to do.

I want to replace the a listbox control with a listview control.
.
20231129003902.png
20231129003902.png (73.68 KiB) Viewed 486 times
.

I am using this structure.
.
20231128222529.png
20231128222529.png (58.4 KiB) Viewed 486 times
.
and this is how it functions.
.
bmm listview.gif
bmm listview.gif (290.39 KiB) Viewed 486 times
.

Code: Select all

project := This.SelectedProject
window := This.Projects[ project ].SelectedWindow
element := This.Projects[ project ].Windows[ window ].SelectedWindowElement

This.Projects[ project ].Windows[ window ].WindowElements[ element ].ElementType 	:= "Add"
This.Projects[ project ].Windows[ window ].WindowElements[ element ].Param1 		:= "Blah blah"
This.Projects[ project ].Windows[ window ].WindowElements[ element ].Param2 		:= "Blah blah"

just me
Posts: 9534
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Gui Listview questions  Topic is solved

Post by just me » 29 Nov 2023, 03:12

Hi @Hellbent,
  1. You need to specify the columns for the ListView.
  2. You should use the vName option. The names are associated with the Gui window owning the control. +hwndVar variables are 'independend' so you create the same set of variables for each Gui -Loop iteration.
  3. Built-in Functions for ListViews
    All of the following ListView functions operate upon the current thread's default GUI window (which can be changed via Gui, 2:Default). If the default window does not exist or has no ListView controls, all functions return zero to indicate the problem.

    If the window has more than one ListView control, by default the functions operate upon the one most recently added. To change this, specify Gui, ListView, ListViewName, where ListViewName is the name of the ListView's associated variable, its ClassNN as shown by Window Spy or in [v1.1.04+] its HWND. Once changed, all existing and future threads will use the indicated ListView. [v1.1.23+]: A_DefaultListView contains the current setting.

Code: Select all

#NoEnv
Loop, 5	{
	Gui, New, % "+hwndGui" A_Index
	Loop, 5	{
		Gui, Add, Listview, % "w300 vLV" A_Index " +hwndListview" A_Index, Element Type|Param1|Param2 ; you need to specify the columns
	}
	Gui, Show, , Gui%A_Index%
}

F1::
	Gui, %Gui2%:Default     ; set the default Gui
	Gui, ListView, LV3      ; set the third ListView as default
	LV_ModifyCol( 2 , 200 )
	LV_Delete()
	LV_Add( "" , "Add" , "ControlType := ""Button""" , "options := """"" )
	Gui, Show
Return

GuiClose:
Esc::ExitApp

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Gui Listview questions

Post by Hellbent » 02 Dec 2023, 00:07

Thank you @just me.

I am currently toggling a variable so that the listview subroutine calls get ignored while changes are being made to the listview, do you know of a more efficient method of doing it?

Code: Select all

	Set_SelectedWindowElement(){
		local project := This.SelectedProject
		local window := This.Projects[ project ].SelectedWindow
		if( A_GuiEvent = "I" && !This.BusyAddingElement ){
			Gui, % This.WindowElementTab.Hwnd ":Default"
			Gui, ListView , WindowElementsListView
			LV_GetText( selectedWindowElement , LV_GetNext( 0 , "Focused" )  , 1 )
			This.Projects[ project ].Windows[ window ].SelectedWindowElement := selectedWindowElement
			This.Set_WindowElements_ParamControls()
		}
		return 1
	}
	Set_ListViewControl_List(){
		local project := This.SelectedProject
		local window := This.Projects[ project ].SelectedWindow
		local elements := This.Projects[ project ].Windows[ window ].WindowElements
		Gui, % This.WindowElementTab.Hwnd ":Default"
		Gui, ListView , WindowElementsListView
		LV_Delete()
		selectedElement := This.Get_WindowElement()
		This.BusyAddingElement := 1        ;<<<<<<--------    blocks the listview routine [ i.e. Set_SelectedWindowElement() ]
		if( elements.Length() ){
			for k , v in elements	{
				cc := elements[ k ]
				if( A_Index = selectedElement ){
					LV_Add( "Select" , A_Index , cc.ElementType , cc.Param1 , cc.Param2 , cc.Param3 , cc.Param4 , cc.Param5 , cc.Param6 , cc.Param7 , cc.Param8 , cc.Param9 , cc.Param10 , cc.Param11 )
				}else{
					LV_Add( "" , A_Index , cc.ElementType , cc.Param1 , cc.Param2 , cc.Param3 , cc.Param4 , cc.Param5 , cc.Param6 , cc.Param7 , cc.Param8 , cc.Param9 , cc.Param10 , cc.Param11 )
				}
			}
		}
		sleep , 100
		This.BusyAddingElement := 0
		return 1
	}

just me
Posts: 9534
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Gui Listview questions

Post by just me » 02 Dec 2023, 06:48

Hi @Hellbent,

you can try to replace the variable with:

Code: Select all

GuiControl, -g, WindowElementsListView ; disable the gLabel
...
GuiControl, +gSet_SelectedWindowElement, WindowElementsListView ; restore the gLabel/gFunction
See: https://www.autohotkey.com/docs/v1/lib/GuiControl.htm#options

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Gui Listview questions

Post by Hellbent » 03 Dec 2023, 07:38

Thank you.

Post Reply

Return to “Ask for Help (v1)”