Jump to content

Autosizing Listview Columns


Go to solution Solved by AZJIO,

Recommended Posts

Hello, I am making a listview in my application, to act as a list, the code I am using to create the listview is such:

Global $convolist = GUICtrlCreatelistview("0|0|1|1|2|2|3|3|4|4|5|5|6|6|7|7|8|8|9|9",230,60,633,75,16396,524801)

Each column name is hidden, and each column will have first a set of data, and then an [x] in the next over like Document1|[x]|Document2|[x], I am sure it will not be hard for me to detect when and which X is clicked, but I am having another problem.

It seems that there is no property to resize the listview as text items are added, and I could not find a function to resize a specific cell in the listview, is there a way that I can resize the cells to the width of the text that they are going to contain?

Thanks for your time looking at my help request!

Link to comment
Share on other sites

#include <GuiListView.au3>
_GUICtrlListView_SetColumnWidth($hWnd, $iCol, $iWidth)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Solution

#include <ListViewConstants.au3>

Local $hGUI, $ListView

$hGUI = GUICreate("ListView", 540, 360, 100, 200)
GUISetBkColor(0xd5d2af)

$ListView = GUICtrlCreateListView("Col1|Col2|Col3|Col4", 10, 10, 520, 340)
; GUICtrlSetBkColor(-1, 0xFFFEEE)
For $t = 1 To Random(1, 10, 1)
    $str = ''
    For $i = 1 To 4
        For $j = 1 To Random(1, 10, 1)
            $str &= Chr(Random(65, 90, 1))
        Next
        $str &= '|'
    Next
    $str = StringTrimRight($str, 1)
    GUICtrlCreateListViewItem($str, $ListView)
Next

GUISetState()

Sleep(1500)
For $i = 0 To 3
    GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1) ; $LVSCW_AUTOSIZE
    GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -2) ; $LVSCW_AUTOSIZE_USEHEADER
Next

Do
Until GUIGetMsg() = -3

Link to comment
Share on other sites

....

For $i = 0 To 3
    GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1) ; $LVSCW_AUTOSIZE
    GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -2) ; $LVSCW_AUTOSIZE_USEHEADER
Next

....

 

beautiful, ...power of messages....

excuse me   AZJIO

where can be found a "list" of messages accepted by various controls and allowed parameters?

thanks

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Those are documented on MSDN. To get the const values I always do a Google search for something like "Const LVM_SETCOLUMNWIDTH". But most messages are already in-cooperated into the existing UDFs anyhow, check _GUICtrlListView_SetColumnWidth().

Link to comment
Share on other sites

ok,

thanks Kafu

.... sometimes the "limit" of the internet is its vastness .....

Edited by Pincopanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

I can make a question on the same subject?

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

$hGUI = GUICreate("Form", 539, 347, -1, -1)
$hListView = GUICtrlCreateListView("Column", 150, 25, 175, 250)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, -2)
GUISetState(@SW_SHOW)

Sleep(1000)

GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

How to have scrollable listview with the vertical scrolling but "hide" the unaestethic orizzontal scrollbar?

Link to comment
Share on other sites

... well just add this 2 lines ....

.....
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)

; add this 2 lines

    GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 0, -1) ; $LVSCW_AUTOSIZE
    GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 0, -2) ; $LVSCW_AUTOSIZE_USEHEADER

While 1
.....

( thanks to AZJIO >#4) ;)

Edited by Pincopanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

What's wrong with just using _GUICtrlListView_SetColumnWidth? Then you don't have to mess around with all that message sending stuff (if you're a novice.)

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I'm sorry guinness
I modified
MyEarth's listing (line 16) following your advice,

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

$hGUI = GUICreate("Form", 539, 347, -1, -1)
$hListView = GUICtrlCreateListView("Column", 150, 25, 175, 250)
_GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE) ; <- used thi instead of GUICtrlSendMsg()
; GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, -2)
GUISetState(@SW_SHOW)

Sleep(1000)

GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)
GUICtrlCreateListViewItem("adsdasadsadsads", $hListView)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

but the listbox is displayed with a strange look

where am I wrong?

thanks

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

No need to be sorry. This looks fine to me.

#include <GUIConstantsEx.Au3>
#include <GUIListView.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('')
    Local $iListView = GUICtrlCreateListView('Column', 5, 5, 390, 390)
    GUISetState(@SW_SHOW, $hGUI)

    For $i = 1 To 20
        GUICtrlCreateListViewItem('adsdasadsadsads', $iListView)
    Next
    _GUICtrlListView_SetColumnWidth($iListView, 0, $LVSCW_AUTOSIZE) ; <- used thi instead of GUICtrlSendMsg()


    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc   ;==>Example

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

ok
I need to move _GUICtrlListView_SetColumnWidth after GUICtrlCreateListViewItem, (so the listview takes a better look.
)

However, if you add a new row with GUICtrlCreateListViewItem with a length greater than the previous ones after the  _GUICtrlListView_SetColumnWidth, it must be invoked again to adjust the new ColumnWidth, I was hoping that it did automatically.... :)

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

No, because it can't predict what item lengths will be posted in the future. It's basically like double-clicking on the column, but without the need for a mouse.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I do not was claiming a "clairvoyant" listview :blink:, perhaps a kind of an internal "OnChange" event managed in the listview's background could do... :)

Edited by Pincopanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Look at WM_NOTIFY and LVN_INSERTITEM.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

#include <ListViewConstants.au3>

Local $hGUI, $ListView

$hGUI = GUICreate("ListView", 540, 360, 100, 200)
GUISetBkColor(0xd5d2af)

$ListView = GUICtrlCreateListView("Col1|Col2|Col3|Col4", 10, 10, 520, 340)
; GUICtrlSetBkColor(-1, 0xFFFEEE)
For $t = 1 To Random(1, 10, 1)
    $str = ''
    For $i = 1 To 4
        For $j = 1 To Random(1, 10, 1)
            $str &= Chr(Random(65, 90, 1))
        Next
        $str &= '|'
    Next
    $str = StringTrimRight($str, 1)
    GUICtrlCreateListViewItem($str, $ListView)
Next

GUISetState()

Sleep(1500)
For $i = 0 To 3
    GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1) ; $LVSCW_AUTOSIZE
    GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -2) ; $LVSCW_AUTOSIZE_USEHEADER
Next

Do
Until GUIGetMsg() = -3

I love you! Thanks. This worked great.

Edit: One other question if I may though, when I detect clicking on the listview, I can't seem to recall how to get the current element clicked, Is there a way to get the text and id of the element that is clicked, on every click?

Edited by nullschritt
Link to comment
Share on other sites

Search for WM_NOTIFY in the help file. Example is already present, but you will have to swap out the UDF listview for the native version.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Search for WM_NOTIFY in the help file. Example is already present, but you will have to swap out the UDF listview for the native version.

I'm able to get an output like so:

+======================================================
-->Line(0067):  $NM_CLICK
--> hWndFrom:   0x0008145A
-->IDFrom:  21
-->Code:    -2
-->Index:   -1
-->SubItem: 0
-->NewState:    0
-->OldState:    19329680
-->Changed: 0
-->ActionX: 0
-->ActionY: 0
-->lParam:  7859784
-->KeyFlags:    0
+======================================================

But how do I get the actual text of what's been clicked?

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