List view with dropdown list

Get help with using AutoHotkey and its commands and hotkeys
AHKStudent
Posts: 1052
Joined: 05 May 2018, 12:23

List view with dropdown list

Post by AHKStudent » 11 Jan 2021, 06:37

Does anyone have a current code sample that shows a list view with a dropdown list in one of the cells?

User avatar
Epialis
Posts: 722
Joined: 02 Aug 2020, 22:44

Re: List view with dropdown list

Post by Epialis » 11 Jan 2021, 16:35

Simplest way I can write it... Hope it helps.

Code: Select all

Dropdown := ["One", "Two", "Three", "Four", "Five", "Six"]
dropList =
For index, thisBook in Dropdown
	dropList .= "|" A_Index "-" Dropdown[A_Index]
Gui, Add, DropDownList, x10 y10 w132, % dropList
Gui, Show

Esc::ExitApp

User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: List view with dropdown list

Post by mikeyww » 11 Jan 2021, 17:14

Looks good, but as far as I know, this is not a listview.

User avatar
Epialis
Posts: 722
Joined: 02 Aug 2020, 22:44

Re: List view with dropdown list

Post by Epialis » 11 Jan 2021, 17:19

mikeyww wrote:
11 Jan 2021, 17:14
Looks good, but as far as I know, this is not a listview.
Oh my... u're right... :oops: :oops: What happens when you just wake up. :headwall:

AHKStudent
Posts: 1052
Joined: 05 May 2018, 12:23

Re: List view with dropdown list

Post by AHKStudent » 11 Jan 2021, 17:21

thanks for the attempt to help, as mike pointed out, this is not a list view.

User avatar
Epialis
Posts: 722
Joined: 02 Aug 2020, 22:44

Re: List view with dropdown list

Post by Epialis » 11 Jan 2021, 17:23

AHKStudent wrote:
11 Jan 2021, 17:21
thanks for the attempt to help, as mike pointed out, this is not a list view.
haha, sorry... I got half right... it is a dropdown :oops: :oops:

User avatar
Epialis
Posts: 722
Joined: 02 Aug 2020, 22:44

Re: List view with dropdown list

Post by Epialis » 11 Jan 2021, 18:27

Okay, I lost the link somehow, but how about this? It will show what is in your folder and put it into a listview... depending on what you choose in the dropdown. I was going to post the link but lost it :( I changed it to a folder on my desktop and it worked. Hopefully I'm understanding you. If not, sorry.. I'm trying. So many have helped me.. just wanna return that; what a community is all about.

Code: Select all

/*
    this script copies selected/marked  from c:\testB   to  c:\testC
    copy with button or rightclick 
*/

#NoEnv
#SingleInstance force
SetBatchLines,-1
setworkingdir, %a_scriptdir%

DSCPLN = A
CENTRALPATH = c:\testB                      ;for test
Gui, Add, DropDownList, Choose1 vDiscipline gGetFolder, Architecture|Interiors|Structure
Gui, Add, Text,, Select which central files to copy locally:

Gui, Add, ListView, r10 w400 Checked altsubmit vMLV1 gMLV2, Name|Size

Loop, %CENTRALPATH%\*.*
    LV_Add("", A_LoopFileName, A_LoopFileSize)

LV_ModifyCol()                  ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")      ; For sorting purposes, indicate that column 2 is an
LV_ModifyCol(2, 60)             ; Make the Size column at little wider to reveal its header.

Gui, Add, Button, Default, Start Copy
Gui, Add, Button, x+20, Cancel
Gui, Show
return
;------------------------------------------------

;-----------------------------------------------------------
MLV2:
Gui,submit,nohide
Gui,ListView,MLV1
  RN:=LV_GetNext("C")
  RF:=LV_GetNext("F")
  GC:=LV_GetCount()

if A_GuiEvent = Normal
   {
   if (RF="" OR RF=0)
      return
   LV_GetText(C1,A_EventInfo,1)
   LV_GetText(C2,A_EventInfo,2)
   }

;---- copy all marked -----------
if A_GuiEvent = Rightclick
   {
   C1x=
   RF = 0
   Loop
     {
     RF:=LV_GetNext(RF)
     if RF=0
        break
     LV_GetText(C1_Temp, RF, 1)
     C1x = %C1x%`n%C1_Temp%
     }

  if C1x !=
     {
     MsgBox, 4, ,Want you copy %C1x% to c:\testc ?
     IfMsgBox,No
         Return
     Else
          {
         StringSplit,D,C1x,`n
         loop,%D0%
             {
              DY=%A_INDEX%                            ;    1 2 3
              if DY=1
                 continue
              DX:=D%A_INDEX%                          ;string
              msgbox,%centralpath%\%DX%               ;msgbox for control
              Filecopy,%centralpath%\%DX%,c:\testc    ;copy to c:\testc
              }
          }
      }
run,c:\testc
return
  }
return
;--------------------------------------------------------------------



;------------- copy checked ----------------------------------------
ButtonStartCopy:
gui,submit,nohide
RNM =0
Loop
    {
    RNM := LV_GetNext(RNM,"checked")
    if not RNM
        break
    LV_GetText(C1,RNM,1)
    msgbox,%centralpath%\%C1%                ;msgbox for control
    Filecopy,%centralpath%\%C1%,c:\testc    ;copy to c:\testc
    }
run,c:\testc                                  ;opens folder where copied
return
;-------------------------------------------------------------



;-----------------------------------
GetFolder:
Gui,submit,nohide
GuiControl, -Redraw, MyListView
If Discipline = Architecture
   {
   CENTRALPATH = C:\Users\dclar\OneDrive\Desktop\listview
   }
If Discipline = Interiors
   {
   msgbox,W:\I\BIM
   CENTRALPATH = W:\I\BIM
   }
If Discipline = Structure
   {
   msgbox,C:\testB
   CENTRALPATH =C:\testb
   }

FILLLIST:
LV_Delete()                       ; Clear the list view first
GuiControl, -Redraw, MLV1
Loop, %CENTRALPATH%\*.*
    LV_Add("", A_LoopFileName, A_LoopFileSize)

LV_ModifyCol()                 ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")     ; For sorting purposes, indicate that column 2 is an
LV_ModifyCol(2, 60)            ; Make the Size column at little wider to reveal its header.
GuiControl, +Redraw, MLV1
Return
;---------------------------

ButtonCancel:
GuiClose:
exitapp
;----------------------------------------------------------------------------
Found the link:

https://autohotkey.com/board/topic/24413-dropdownlist-controlling-a-listview/

AHKStudent
Posts: 1052
Joined: 05 May 2018, 12:23

Re: List view with dropdown list

Post by AHKStudent » 11 Jan 2021, 22:54

Epialis wrote:
11 Jan 2021, 18:27
Okay, I lost the link somehow, but how about this? It will show what is in your folder and put it into a listview... depending on what you choose in the dropdown. I was going to post the link but lost it :( I changed it to a folder on my desktop and it worked. Hopefully I'm understanding you. If not, sorry.. I'm trying. So many have helped me.. just wanna return that; what a community is all about.

Code: Select all

/*
    this script copies selected/marked  from c:\testB   to  c:\testC
    copy with button or rightclick 
*/

#NoEnv
#SingleInstance force
SetBatchLines,-1
setworkingdir, %a_scriptdir%

DSCPLN = A
CENTRALPATH = c:\testB                      ;for test
Gui, Add, DropDownList, Choose1 vDiscipline gGetFolder, Architecture|Interiors|Structure
Gui, Add, Text,, Select which central files to copy locally:

Gui, Add, ListView, r10 w400 Checked altsubmit vMLV1 gMLV2, Name|Size

Loop, %CENTRALPATH%\*.*
    LV_Add("", A_LoopFileName, A_LoopFileSize)

LV_ModifyCol()                  ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")      ; For sorting purposes, indicate that column 2 is an
LV_ModifyCol(2, 60)             ; Make the Size column at little wider to reveal its header.

Gui, Add, Button, Default, Start Copy
Gui, Add, Button, x+20, Cancel
Gui, Show
return
;------------------------------------------------

;-----------------------------------------------------------
MLV2:
Gui,submit,nohide
Gui,ListView,MLV1
  RN:=LV_GetNext("C")
  RF:=LV_GetNext("F")
  GC:=LV_GetCount()

if A_GuiEvent = Normal
   {
   if (RF="" OR RF=0)
      return
   LV_GetText(C1,A_EventInfo,1)
   LV_GetText(C2,A_EventInfo,2)
   }

;---- copy all marked -----------
if A_GuiEvent = Rightclick
   {
   C1x=
   RF = 0
   Loop
     {
     RF:=LV_GetNext(RF)
     if RF=0
        break
     LV_GetText(C1_Temp, RF, 1)
     C1x = %C1x%`n%C1_Temp%
     }

  if C1x !=
     {
     MsgBox, 4, ,Want you copy %C1x% to c:\testc ?
     IfMsgBox,No
         Return
     Else
          {
         StringSplit,D,C1x,`n
         loop,%D0%
             {
              DY=%A_INDEX%                            ;    1 2 3
              if DY=1
                 continue
              DX:=D%A_INDEX%                          ;string
              msgbox,%centralpath%\%DX%               ;msgbox for control
              Filecopy,%centralpath%\%DX%,c:\testc    ;copy to c:\testc
              }
          }
      }
run,c:\testc
return
  }
return
;--------------------------------------------------------------------



;------------- copy checked ----------------------------------------
ButtonStartCopy:
gui,submit,nohide
RNM =0
Loop
    {
    RNM := LV_GetNext(RNM,"checked")
    if not RNM
        break
    LV_GetText(C1,RNM,1)
    msgbox,%centralpath%\%C1%                ;msgbox for control
    Filecopy,%centralpath%\%C1%,c:\testc    ;copy to c:\testc
    }
run,c:\testc                                  ;opens folder where copied
return
;-------------------------------------------------------------



;-----------------------------------
GetFolder:
Gui,submit,nohide
GuiControl, -Redraw, MyListView
If Discipline = Architecture
   {
   CENTRALPATH = C:\Users\dclar\OneDrive\Desktop\listview
   }
If Discipline = Interiors
   {
   msgbox,W:\I\BIM
   CENTRALPATH = W:\I\BIM
   }
If Discipline = Structure
   {
   msgbox,C:\testB
   CENTRALPATH =C:\testb
   }

FILLLIST:
LV_Delete()                       ; Clear the list view first
GuiControl, -Redraw, MLV1
Loop, %CENTRALPATH%\*.*
    LV_Add("", A_LoopFileName, A_LoopFileSize)

LV_ModifyCol()                 ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")     ; For sorting purposes, indicate that column 2 is an
LV_ModifyCol(2, 60)            ; Make the Size column at little wider to reveal its header.
GuiControl, +Redraw, MLV1
Return
;---------------------------

ButtonCancel:
GuiClose:
exitapp
;----------------------------------------------------------------------------
Found the link:

https://autohotkey.com/board/topic/24413-dropdownlist-controlling-a-listview/
The image shows you what I am looking to do

Image

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

Re: List view with dropdown list

Post by Hellbent » 12 Jan 2021, 07:25

Not a real solution submission, just playing around to make a little prototype.

Code: Select all

#SingleInstance,Force

OnMessage(0x201,"MessageHandler")

global Names := ["Bob1","Amanda","Sammy","Jim","Richard","Barry","Barb","Hellbent","Bob","Amanda","Sammy","Jim","Richard","Barry","Barb","Hellbent","Bob","Amanda","Sammy","Jim","Richard","Barry","Barb","Hellbent","Bob","Amanda","Sammy","Jim","Richard","Barry","Barb","HellbentLast"] 
Address := ["123 Blah court","234 Somewhere St","987 I don't care","647 dfgskh","43856 dskfg","65434 gsdgsdds","444 sdgg","543543 dfwgr","123 Blah court","234 Somewhere St","987 I don't care","647 dfgskh","43856 dskfg","65434 gsdgsdds","444 sdgg","543543 dfwgr","123 Blah court","234 Somewhere St","987 I don't care","647 dfgskh","43856 dskfg","65434 gsdgsdds","444 sdgg","543543 dfwgr","123 Blah court","234 Somewhere St","987 I don't care","647 dfgskh","43856 dskfg","65434 gsdgsdds","444 sdgg","543543 dfwgr"]

Gui, 1:+AlwaysOnTop -DPIScale hwndGui1Hwnd
Gui, 1:Color, 232426
Gui, 1:Font, cBlack s10 Bold, Segoe UI
Gui, 1:Margin, 3, 3


Gui, 1:Show, w750 h450, Not A Real Solution!!!!

Gui, 2:-DPIScale +Parent1 -Caption
Gui, 2:Show,x3 y53 w694 h394

Gui, 3:-DPIScale +Parent2 -Caption
th := Names.Length()*(36)
Gui, 3:Show,x0 y0 w694 h%th%

pos3 := 0
if(A_ScreenDPI=96)
		fs := 8
	else 
		fs := 7
Gui, 1:Font, cBlack s%fs% Bold, Segoe UI

Gui,1:Add,Text,cWhite x3 y23 w250 h30 Center 0x201, Name:
Gui,1:Add,Text,cWhite x256 y23 w60 h30 Center 0x201, Grade:
Gui,1:Add,Text,cWhite x319 y23 w365 h30 Center 0x201, Address:

Gui,1:Add,Button, x700 y53 w46 h25 gMoveDown, Up
Gui,1:Add,Slider, x700 y120 w46 h250 Range0-600 BackgroundBlack AltSubmit vertical vSlider1 gSliderMove,0
Gui,1:Add,Button, x700 y420 w46 h25 gMoveUp, Down
GuiControl,1:Focus,Slider1

Loop, % Names.Length(){
	EndYV := CreateRow(Names[A_Index],Address[A_Index])
}

return
GuiClose:
GuiContextMenu:
*ESC::
	ExitApp

MoveUp:
	Pos3 -= 31
	if !(Pos3>-(EndYV-396))
		Pos3:= -(EndYV-396)
	GuiControl,1:,Slider1,% -Pos3
	Gui, 3:Show, % "x0 y" Pos3
	return

MoveDown:
	Pos3 += 31
	if !(Pos3<(0))
		Pos3 := 0
	GuiControl,1:,Slider1,% -Pos3
	Gui, 3:Show, % "x0 y" Pos3
	return

SliderMove:
	Gui,1:Submit,NoHide
	Pos3 := -Slider1
	Gui, 3:Show, % "x0 y" Pos3
	return

CreateRow(Names,Address){
	static Row := 0, Tog, xv := 3, yv := 3, Grades := "A|B|C|D|E|F"
	
	Name := "Row_" ++Row
	Width := 900
	Height := 25 + 6
	xMargin := 3
	yMargin := 3
	yv := (Row*Height+yMargin)-(Height+yMargin)
	EndYV := yv + 31
	if(A_ScreenDPI=96)
		fs := 10
	else 
		fs := 8
	Gui, % Name ":New", +Parent3 -Caption -DPIScale
	Gui, % Name ":Color", % (Tog:=!Tog)?("FFFEAA"):("FFFFFF")
	Gui, % Name ":Margin", %xmargin%, 3
	Gui, % Name ":Font", s%fs% Bold, Segoe UI
	
	Gui, % Name ":Add", Edit, xm ym w250 h25 ReadOnly  ,% Names
	Gui, % Name ":Add", DDL, % "x+" xMargin " ym w60 h25 r6 -Theme", % Grades
	Gui, % Name ":Add", Edit, % "x+" xMargin " ym w365 h25 ReadOnly", % Address
	
	Gui, % Name ":Show", % "x" xv " y" yv " w" Width " h" Height
	
	return EndYV
	
}

MessageHandler(){
	if(temp:=SubStr(A_Gui,1,4)="Row_"){
		Loop, % Names.Length()	{
			Gui, % "Row_" A_Index ":Color", % (Tog:=!Tog)?("FFFEAA"):("FFFFFF")
		}
		Gui, % A_Gui ":Color", 3399aa
	}
		
}


.
temp gif.gif
temp gif.gif (926.71 KiB) Viewed 230 times

AHKStudent
Posts: 1052
Joined: 05 May 2018, 12:23

Re: List view with dropdown list

Post by AHKStudent » 12 Jan 2021, 07:45

@Hellbent thats looks very cool, I wish list views could look like that. What you built is perfect if someone have a few hundred entries of something they want to access and easily modify. Looks amazing. :thumbup: :thumbup:

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

Re: List view with dropdown list

Post by Hellbent » 12 Jan 2021, 07:57

@AHKStudent Thanks. To be honest, I've never actually used a real listview before so I don't know much about what they do or how to use them. :lol:
This is just my best guess. Of course I would want to add a few other features such as adjustable column size, sorting each column, etc. etc.

User avatar
Epialis
Posts: 722
Joined: 02 Aug 2020, 22:44

Re: List view with dropdown list

Post by Epialis » 12 Jan 2021, 08:28

I'm genuinely amazed at the level of knowledge in this place. Looks great! :bravo: :bravo:

AHKStudent
Posts: 1052
Joined: 05 May 2018, 12:23

Re: List view with dropdown list

Post by AHKStudent » 12 Jan 2021, 13:01

AHKStudent wrote:
12 Jan 2021, 07:45
@Hellbent thats looks very cool, I wish list views could look like that. What you built is perfect if someone have a few hundred entries of something they want to access and easily modify. Looks amazing. :thumbup: :thumbup:
In C# there is a something called datagridview that is in line of what you are building here. Thanks

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

Re: List view with dropdown list

Post by Hellbent » 15 Jan 2021, 11:47

@AHKStudent

I did a little more work on prototyping a listview control this morning. I'm still just working out how I want to do things to work but I think I have a bunch of the nuts and bolts figured out. I didn't bother to add in sliders to scroll the page in this one, only because I already added that to the first POC.


*This requires the GDIP Library https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517

If you Left Click [ Row 3 | Column 2 ] (The "Blue A25AAB") while holding shift, it will display a DropDownList

Code: Select all

;***************************************************************************************************
#Include <My Altered Gdip Lib>  ;<------       Replace with your copy of GDIP
;***************************************************************************************************
#SingleInstance, Force
#NoEnv
ListLines, Off
SetBatchLines, -1
OnExit, *ESC
pToken := GDIP_StartUp()
MyList2 := ["This is the first string and it is really really really really really really long","B9160B","A25AAB","FF8319","49134F","5B0FD5","CA1969","3163D9","D73AB6","A009D9","F43A91","5B0FD5","B9160B","848B04","861E5D","B9160B","A25AAB","FF8319","49134F","5B0FD5","CA1969","3163D9","D73AB6","A009D9","F43A91","5B0FD5","B9160B","848B04","861E5D","B9160B","A25AAB","FF8319","49134F","5B0FD5","CA1969","3163D9","D73AB6","A009D9","F43A91","5B0FD5","B9160B","848B04","861E5D"]
/*
MainBitmap := {} 
MainBitmap.pBitmap := Gdip_CreateBitmap( This.Width, This.Height)
MainBitmap.G := Gdip_GraphicsFromImage( MainBitmap.pBitmap )
Gdip_SetSmoothingMode( MainBitmap.G , 1 )
*/
Font := "Times"
FontSize := 12
FontOptions := "s" FontSize ;" Bold" ;Rendering5"
FontColor := "0xFFCDCDCD"
Width1 := [11,250,100,200]
Height := 400
BackgroundColor := "0xFF23282a"
Spacing := 5
Colors := ["0xFF22262A","0xFF22262A","0xFF880000","0xFFFFFF00"]
FontColors := ["0xFFFFFFFF","0xFF22AAFF","0xFFFFFF00","0xFF880000"]
xpos := 0, ypos := 0 , wpos := 0, hPos := 0
Gui,1:+AlwaysOnTop -DPIScale 
Gui,1:Color,13181a
Gui,1:Add,Text, % "x" xpos " y" ypos " w" wpos " h" hpos " BackgroundTrans gTestDDL hwndTestTriggerHwnd"
Gui,1:Margin,5,5
x:=5
Loop, 4	{
	if(A_Index!=1){
		Column%A_Index% := New Column(MyList2, Font, FontOptions, FontColors[A_Index], Width1[A_Index], Height , Colors[A_Index], Spacing)
		Gui,1:Add,Text,% "x" x " ym w" Width1[A_Index] " h" Height " hwndhwnd" A_Index " 0xE gOnClick"
	}else{
		Column%A_Index% := New Column(MyList2, Font, FontOptions, FontColors[A_Index], "" , Height , BackgroundColor, Spacing)
		Gui,1:Add,Text,% "xm ym w" Column%A_Index%.Width " h" Height " hwndhwnd" A_Index " 0xE gOnClick"
		FirstWidth := Column%A_Index%.Width
	}
	x += Column%A_Index%.Width 
	SetImage(hwnd%A_Index%, Column%A_Index%.Bitmap)	
}
Gui,1: Add, Text,cLime xm y+30,Adjust Margin  spacing
Gui,1:Add,Slider,x+10  w300 TickInterval10 Range1-100 AltSubmit Thick20 gTestSlider hwndSliderHwnd1, Spacing
Gui,1: Add, Text,cLime x+30 hwndspacinghwnd, """"""""
Gui,1: Add, Text,cLime xm y+30,Adjust Font Size
Gui,1:Add,Slider,x+10 w300  Range6-244 AltSubmit Thick30 gTestSlider2 hwndSliderHwnd2,% FontSize
Gui,1: Add, Text,cLime x+30 hwndfontsizehwnd, """"""""
xpos := 5 + Column1.Width, ypos := 5 + (Column1.CharHeight * 2) , wpos := Column2.Width , hPos := Column2.CharHeight
GuiControl,1:Move,% TestTriggerHwnd, % "x" xpos " y" ypos " w" wpos " h" hPos
Gui,1:Show,,ListView
gosub, TempUpdateFunction
return
GuiClose:
GuiContextMenu:
*ESC:: 
	GDIP_SHUTDOWN(pToken)
	ExitApp
TestDDL:
	if(!GetKeyState("Shift")){
		gosub, Onclick
		return
	}
	SoundBeep, 500
	CoordMode, Mouse, Screen
	MouseGetPos, ttx, tty
	gosub, Onclick
	Gui,99:New,+Owner1 
	Gui,99:Add,DDL,xm ym w300 r10 gFakeSubmit hwndfakehwnd,A||B|C|D|E|F|
	Gui,99:Show,% " x" ttx - 160 " y" tty - 40 , ListView
	return
FakeSubmit:
	GuiControlGet,out,99:,% fakehwnd
	Gui,99:Destroy
	MyList2[3] := out
	gosub, TempUpdateFunction
	return
OnClick:
	Coordmode, Mouse, Client
	MouseGetPos, tx, ty
	GetClick := Floor(((ty - 5) / Column1.CharHeight) +1 )
	gosub, TempUpdateFunction
	return
TestSlider:
	GuiControlGet,Spacing , 1:, % SliderHwnd1
	gosub, TempUpdateFunction
	sleep, 30
	return
TestSlider2:
	GuiControlGet,FontSize , 1:, % SliderHwnd2
	gosub, TempUpdateFunction
	sleep, 30
	return
TempUpdateFunction:
	Loop, 4	{
		DeleteObject(Column%A_Index%.Bitmap)
		Column%A_Index% := ""
		Column%A_Index% := New Column(MyList2, Font, "s" FontSize , FontColors[A_Index],  (A_Index=1)?(FirstWidth):(Width1[A_Index]), Height , Colors[A_Index], Spacing,GetClick)
	}
	xpos := 5 + Column1.Width, ypos := 5 + (Column1.CharHeight * 2) , wpos := Column2.Width , hPos := Column2.CharHeight
	GuiControl,1:MoveDraw,% TestTriggerHwnd, % "x" xpos " y" ypos " w" wpos " h" hPos
	Loop, 4 
		SetImage(hwnd%A_Index%, Column%A_Index%.Bitmap)
	GuiControl,1:,% FontSizeHwnd, % FontSize
	GuiControl,1:,% SpacingHwnd, % Spacing
	return
Class Master	{

}
Class Column	{
	__New(ColumnList := "", Font := "Arial", FontOptions := "s12 Bold", FontColor := "0xFFFFFFFF", Width := "",Height := "", BackgroundColor := "0xFF22272A", Spacing := 8, Click := ""){
		This.Spacing := Spacing
		This.GridColor := "0xFF00070A"
		This.List := ColumnList
		This.Font := Font
		This.FontOptions := FontOptions
		This.FontColor := "" FontColor
		This.BackgroundColor := "" BackgroundColor
		(Width)?(This.Width := Width):(This.Width := This._GetLongestStringWidth())
		This.CharHeight := This._GetCharHeight() + This.Spacing
		(Height)?(This.Height := Height):(This.Height := This.List.Length() * This.CharHeight,This.Height -= This.Spacing / 2 - 1)
		This.Click := Click
		This._CreateBitmap()
	}
	_CreateBitmap(){
		local G, Brush, y := This.Spacing/2, y2 := 0
		pBitmap := Gdip_CreateBitmap( This.Width, This.Height), G := Gdip_GraphicsFromImage( pBitmap ), Gdip_SetSmoothingMode( G , 3 )
		Brush := Gdip_BrushCreateSolid( This.BackgroundColor ), Gdip_FillRectangle( G , Brush , -1 , -1 , This.Width+2, This.Height+2 ), Gdip_DeleteBrush( Brush )
		Brush1 := Gdip_BrushCreateSolid( This.FontColor)
		Pen := Gdip_CreatePen( This.GridColor , 1 )
		if(IsObject(This.List)){
			Loop, % This.List.Length()	{
				(A_Index!=1)?(y := (A_Index - 1) * This.CharHeight):(y := This.Spacing/4)
				if(A_Index = This.Click)
					Brush := Gdip_BrushCreateSolid( "0xFF3377cc"), Gdip_FillRectangle( G , Brush , -1 , y-This.Spacing/2 , This.Width+2, This.CharHeight ), Gdip_DeleteBrush( Brush )
				Gdip_TextToGraphics( G , This.List[A_Index], This.FontOptions " c" Brush1 " Left NoWrap x" This.Spacing/2 " y" y , This.Font , This.Width, This.CharHeight )
				y2 :=  A_Index * This.CharHeight - This.Spacing /2
				Gdip_DrawLine( G , Pen , 0 , y2, This.Width , y2 )
			}
		}
		Gdip_DrawLine( G , Pen , This.Width-1 , -1, This.Width-1 , This.Height+2)
		Gdip_DrawLine( G , Pen , 0 , -1, 0, This.Height+2)
		Gdip_DrawLine( G , Pen , -1 , 0, This.Width+2, 0)
		Gdip_DeletePen( Pen ), Gdip_DeleteBrush( Brush ), Gdip_DeleteBrush( Brush1 ), Gdip_DeleteGraphics( G )
		This.Bitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
		Gdip_DisposeImage(pBitmap)
	}
	_GetLongestStringWidth(){
		local LongestElement := 0, pBitmap, G, Brush, width
		pBitmap := Gdip_CreateBitmap( 10,10), G := Gdip_GraphicsFromImage( pBitmap ), Gdip_SetSmoothingMode( G , 2 )
		Brush := Gdip_BrushCreateSolid( This.FontColor)
		if(IsObject(This.List)){
			Loop, % This.List.Length()	{
				if((width := StrSplit( Gdip_TextToGraphics( G , This.List[A_Index], This.FontOptions " c" Brush " Left NoWrap x" 0 " y" 0 , This.Font , 10000, 10000  ),"|","|"  )[3])>LongestElement)
					LongestElement := width
			}
		}
		Gdip_DeleteBrush( Brush ), Gdip_DeleteGraphics( G ), Gdip_DisposeImage( pBitmap )
		return LongestElement + This.Spacing 
	}
	_GetCharHeight(){
		local pBitmap, G, Brush, height
		pBitmap := Gdip_CreateBitmap( 10,10), G := Gdip_GraphicsFromImage( pBitmap ), Gdip_SetSmoothingMode( G , 2 )
		Brush := Gdip_BrushCreateSolid( This.FontColor)
		height := StrSplit( Gdip_TextToGraphics( G , "ABCDEFGHIJKLMNOPQRSTUVWXYZ/[(", This.FontOptions " c" Brush " Left NoWrap x" 0 " y" 0 , This.Font , 10000, 10000  ),"|","|"  )[4]
		Gdip_DeleteBrush( Brush ), Gdip_DeleteGraphics( G ), Gdip_DisposeImage( pBitmap )
		return height
	}
	;~ __Delete(){
		
	;~ }
}


.
20210115113056.png
20210115113056.png (75.92 KiB) Viewed 132 times

AHKStudent
Posts: 1052
Joined: 05 May 2018, 12:23

Re: List view with dropdown list

Post by AHKStudent » 16 Jan 2021, 05:23

@Hellbent this is obviously lightyears ahead of the current listview, but it does look like its a heavily customized listview but I dont see any reference to a listview other than the name of the window. I tested the dropdown, works really well, will study this to learn how I can add my data to it, update etc, the ability to customized colors is also something many ask for, thanks again

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

Re: List view with dropdown list

Post by just me » 16 Jan 2021, 09:51

KISS:

Code: Select all

#NoEnv
#SingleInstance, Force
SetBatchLines, -1
Names := ["Bob1","Amanda","Sammy","Jim","Richard","Barry","Barb","Hellbent","Bob","Amanda","Sammy","Jim"
         ,"Richard","Barry","Barb","Hellbent","Bob","Amanda","Sammy","Jim","Richard","Barry","Barb","Hellbent"
         ,"Bob","Amanda","Sammy","Jim","Richard","Barry","Barb","HellbentLast"]
Addrs := ["123 Blah court","234 Somewhere St","987 I don't care","647 dfgskh","43856 dskfg","65434 gsdgsdds"
         ,"444 sdgg","543543 dfwgr","123 Blah court","234 Somewhere St","987 I don't care","647 dfgskh"
         ,"43856 dskfg","65434 gsdgsdds","444 sdgg","543543 dfwgr","123 Blah court","234 Somewhere St"
         ,"987 I don't care","647 dfgskh","43856 dskfg","65434 gsdgsdds","444 sdgg","543543 dfwgr"
         ,"123 Blah court","234 Somewhere St","987 I don't care","647 dfgskh","43856 dskfg","65434 gsdgsdds"
         ,"444 sdgg","543543 dfwgr"]
CBB_Row := 0
CBB_Col := 0
Col1W := 150
Col2W := 50
Col3W := 225
LVW := Col1W + Col2W + Col3W + 25
Gui, LV:Default
Gui, Margin, 10, 
Gui, Add, Text, CBlue, Ctrl+LBUTTON within the second column will show a dropdown list
Gui, Add, ListView, w%LVW% r20 -Multi +Grid +LV0x010000 hwndHLV vVLV gListViewEvents HwndHLV, Name|Grade|Addr
Loop, % Names.Length()
   LV_Add("", Names[A_Index], "", Addrs[A_Index])
LV_ModifyCol(1, Col1W)
LV_ModifyCol(2, Col2W)
LV_ModifyCol(3, Col3W)
Gui, Show, , List view with dropdown list
Gui, DDL:Default
Gui, -Caption +Parent%HLV%
Gui, Margin, 0, 0
Gui, Add, DDL, w%Col2W% vGrade hwndHCBB gDDLEvents, A|B|C|D|E
OnMessage(0x0201, "WM_LBUTTON")
Return
; ======================================================================================================================
ListViewEvents:
Return
; ======================================================================================================================
LVGuiClose:
ExitApp
; ======================================================================================================================
DDLEvents:
GuiControlGet, Grade
If (Grade <> "") {
   Gui, LV:Default
   LV_Modify(CBB_Row, "Col" . CBB_Col, Grade)
   GuiControl, Focus, VLV
}
; ----------------------------------------------------------------------------------------------------------------------
DDLGuiEscape:
Gui, DDL:Hide
Return
; ======================================================================================================================
WM_LBUTTON(W, L, M, H) {
   Global HLV, CBB_Row, CBB_Col
   Gui, DDL:Hide
   If (H = HLV) && (W & 0x0008) { ; Ctrl+LBUTTON within the ListView
      IF (SI := LV_EX_SubItemHitTest(H, L & 0xFFFF, L >> 16)) && (SI = 2) {
         CBB_Row := ErrorLevel + 1
         CBB_Col := SI
         LV_Modify(CBB_Row, "Focus Select")
         LV_GetText(Grade, CBB_Row, CBB_Col)
         If (Grade <> "")
            GuiControl, DDL:ChooseString, Grade, %Grade%
         Else
            GuiControl, DDL:Choose, Grade, 0
         RC := LV_EX_GetSubItemRect(H, CBB_Col, CBB_Row)
         Gui, DDL:Show, % "x" . RC.X . " y" . RC.Y
         Return 0
      }
   }
}
; ======================================================================================================================
; LV_EX_SubItemHitTest - Gets the column (subitem) at the passed coordinates or the position of the mouse cursor.
; ======================================================================================================================
LV_EX_SubItemHitTest(HLV, X := -1, Y := -1) {
   ; LVM_SUBITEMHITTEST = 0x1039 -> http://msdn.microsoft.com/en-us/library/bb761229(v=vs.85).aspx
   VarSetCapacity(LVHTI, 24, 0) ; LVHITTESTINFO
   If (X = -1) || (Y = -1) {
      DllCall("User32.dll\GetCursorPos", "Ptr", &LVHTI)
      DllCall("User32.dll\ScreenToClient", "Ptr", HLV, "Ptr", &LVHTI)
   }
   Else {
      NumPut(X, LVHTI, 0, "Int")
      NumPut(Y, LVHTI, 4, "Int")
   }
   SendMessage, 0x1039, 0, % &LVHTI, , % "ahk_id " . HLV
   Return (ErrorLevel > 0x7FFFFFFF ? 0 : NumGet(LVHTI, 16, "Int") + 1)
}
; ======================================================================================================================
; LV_EX_GetSubItemRect - Retrieves information about the bounding rectangle for a subitem in a list-view control.
; ======================================================================================================================
LV_EX_GetSubItemRect(HLV, Column, Row := 1, LVIR := 0, ByRef RECT := "") {
   ; LVM_GETSUBITEMRECT = 0x1038 -> http://msdn.microsoft.com/en-us/library/bb761075(v=vs.85).aspx
   VarSetCapacity(RECT, 16, 0)
   NumPut(LVIR, RECT, 0, "Int")
   NumPut(Column - 1, RECT, 4, "Int")
   SendMessage, 0x1038, % (Row - 1), % &RECT, , % "ahk_id " . HLV
   If (ErrorLevel = 0)
      Return False
   If (Column = 1) && ((LVIR = 0) || (LVIR = 3))
      NumPut(NumGet(RECT, 0, "Int") + LV_EX_GetColumnWidth(HLV, 1), RECT, 8, "Int")
   Result := {}
   Result.X := NumGet(RECT,  0, "Int"), Result.Y := NumGet(RECT,  4, "Int")
   Result.R := NumGet(RECT,  8, "Int"), Result.B := NumGet(RECT, 12, "Int")
   Result.W := Result.R - Result.X,     Result.H := Result.B - Result.Y
   Return Result
}
; ======================================================================================================================
; LV_EX_GetColumnWidth - Gets the width of a column in report or list view.
; ======================================================================================================================
LV_EX_GetColumnWidth(HLV, Column) {
   ; LVM_GETCOLUMNWIDTH = 0x101D -> http://msdn.microsoft.com/en-us/library/bb774915(v=vs.85).aspx
   SendMessage, 0x101D, % (Column - 1), 0, , % "ahk_id " . HLV
   Return ErrorLevel
}
*Did only some short tests*

Post Reply

Return to “Ask For Help”