Jump to content

[SOLVED] $WS_HSCROLL doesn't work on ListView


Recommended Posts

I have a ListView that allow user to click and drag multiple files into it, but when the path+filename is too long, the listview doesn't display a horizontal scroll.

Tried this without result:

$list = GUICtrlCreateListView('Files', 10, 10, 380, 230, $LVS_REPORT + $WS_HSCROLL)      ; $LVS_REPORT allow mutiple files to be selected

Also

GUICreate($Title, 400, 320, -1, -1, -1, $WS_EX_ACCEPTFILES + $WS_HSCROLL)

What did I do wrong?

Thanks in advance :)

Edited by michaelslamet
Link to comment
Share on other sites

Search scrollbars and Melba23 in the Examples section.

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

  • Moderators

michaelslamet,

You do not need any additional styles - you just need to make the column width wider than the ListView to get horizontal scrollbars: :)

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

$hGUI = GUICreate("Test", 500, 500)

$cListView = GUICtrlCreateListView('Files', 10, 10, 380, 230)
_GUICtrlListView_SetColumnWidth($cListView, 0, 500) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlCreateListViewItem("This is a very long ListView item and therefore should require scrollbars to see it all", $cListView)

GUISetState()

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

You might think of using my StringSize UDF to calculate the length of the each ListView item and make sure you set the column width to be slightly greater than the longest. ;)

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

Guinness and Melba, thanks for the clue and the example!

Using your StringSize UDF solve this!

#include <StringSize.au3>

Global $longest_filename_width = 0
Global $default_listview_width = 376

For $n = 0 to _GUICtrlListView_GetItemCount($list) - 1
      $aSize = _StringSize(_GUICtrlListView_GetItemTextString($list, $n), Default, Default, Default, Default, 0)
      If $aSize[2] > $longest_filename_width Then
         $longest_filename_width = $aSize[2]
      EndIf
Next

If $longest_filename_width > $default_listview_width Then
     _GUICtrlListView_SetColumnWidth($list, 0, $longest_filename_width + 20)
EndIf

Thanks again! :)

Link to comment
Share on other sites

  • Moderators

michaelslamet,

Delighted that we could help. :)

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

Another way to have the ListView show the whole line in a column is this way.

_GUICtrlListView_SetColumnWidth($list, 0, $LVSCW_AUTOSIZE)

This will cause the ListView column to be as wide as the longest item in the column. Letting Windows figure out which one that is is a lot easier than trying to do the math yourself, and stringsize wouldn't be needed in this case.

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

  • Moderators

BrewManNH,

I tried that expecting the result you suggest and it did not work - all I got was a very narrow column:

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

$hGUI = GUICreate("Test", 500, 500)

$cListView = GUICtrlCreateListView('Files', 10, 10, 380, 230)
_GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlCreateListViewItem("This is a very long ListView item and therefore should require scrollbars to see it all", $cListView)

GUISetState()

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

Does it actually work for you? :huh:

M23

Edit: Brain fart on my part - see below. :(

Edited by Melba23

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

Hi Melba and BrewManNH,

I tried it, it actually works :-)

Instead of

_GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlCreateListViewItem("This is a very long ListView item and therefore should require scrollbars to see it all", $cListView)

This is working:

GUICtrlCreateListViewItem("This is a very long ListView item and therefore should require scrollbars to see it all", $cListView)
_GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Link to comment
Share on other sites

On my listview, I have 2 cols, so using $LVSCW_AUTOSIZE on short filename will display a vertical line in the middle of the listview.

Is there any way to tell autoit that this listview only has 1 col?

This is part of my code:

GUICreate($Title, 400, 320, -1, -1, -1, $WS_EX_ACCEPTFILES)
WinSetOnTop($Title, "", 1)                                        ; always stay on top
$list = GUICtrlCreateListView('Files:', 10, 10, 380, 230, $LVS_REPORT)                ; $LVS_REPORT allow mutiple files to be selected
GUICtrlSendMsg($list, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, -1)
Link to comment
Share on other sites

  • Moderators

michaelslamet,

Obvious when you think about it! :doh:

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

This is what I mean:

Let say on the listview we have 2 items:

first item's length is 200

second item's length is 500

our default col width is 400

when we delete first item and then execute $LVSCW_AUTOSIZE, it should be no problem because after that our col width become 500++ is the horizontal scroll is displayed.

the problem is when we delete second item then execute $LVSCW_AUTOSIZE, our list view will now display vertical lines in the middle of list view.

If we need to use "If" to calculate which item has the longest width and how width is that and compare it to our default col width (which is 400), we absolutely need Melba's StringSize UDF, BrewManNH's solution wont work.

Is it correct? Sorry for my noob analysis o:)

Link to comment
Share on other sites

  • Moderators

michaelslamet,

I understood you perfectly. I have an idea and I am trying to get it to work - give me a little while. ;)

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

I would use _GUICtrlListView_GetColumnWidth after resizing it, see if the width is shorter than the width of your ListView control, and if it is narrower, set the width of the column to the width of the listview.

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

Hi BrewmanNH,

Now I understand you perfectly!

This works great:

_GUICtrlListView_SetColumnWidth($list, 0, $LVSCW_AUTOSIZE)
If _GUICtrlListView_GetColumnWidth($list, 0) < $default_listview_width Then
      _GUICtrlListView_SetColumnWidth($list, 0, $default_listview_width)
EndIf

Thank you for providing another method/solution :thumbsup:

Maybe Melba will come out with another ideas :sorcerer:

Link to comment
Share on other sites

  • Moderators

michaelslamet,

This seems to work. Set the column to the max size of the ListView when you create it - when you add/delete an item reset the column width to auto - read the resulting column width and if it is too short then reset the column to the max width: ;)

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

Global $aItems[2] = ["This is a short line", "This is a very long ListView item and therefore should require scrollbars to see it all"]
$iLV_Width = 380
$iMax_Width = $iLV_Width - 17 ; Allow for a vertical scrollbar

$hGUI = GUICreate("Test", 500, 500)

$cListView = GUICtrlCreateListView('Files', 10, 10, $iLV_Width, 230)
; Set width to max
_GUICtrlListView_SetColumnWidth($cListView, 0, $iMax_Width)

GUISetState()

For $i = 0 To 1
    ; Create item
    GUICtrlCreateListViewItem($aItems[$i], $cListView)

    ; Just for testing
    ConsoleWrite("Added item" & @CRLF)
    Sleep(1000)

    ; Set autowidth
    _GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE)
    ; How wide is it?
    $iCurr_Width = _GUICtrlListView_GetColumnWidth($cListView, 0)

    ; Just for testing
    ConsoleWrite("Set to auto" & @CRLF)
    Sleep(1000)

    ; Reset to max if it is now too small
    If $iCurr_Width < $iMax_Width Then
        _GUICtrlListView_SetColumnWidth($cListView, 0, $iMax_Width)
        ; Just for testing
        ConsoleWrite("Set to Max" & @CRLF)
    EndIf

    ; Just for testing
    Sleep(1000)

Next


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

Any use? :)

M23

Edit: Once again we have come up with a similar solution! :D

Edited by Melba23

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

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