michaelslamet Posted May 9, 2013 Share Posted May 9, 2013 (edited) 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 May 9, 2013 by michaelslamet Link to comment Share on other sites More sharing options...
guinness Posted May 9, 2013 Share Posted May 9, 2013 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 9, 2013 Moderators Share Posted May 9, 2013 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 WEndYou 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 michaelslamet 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
michaelslamet Posted May 9, 2013 Author Share Posted May 9, 2013 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 More sharing options...
Moderators Melba23 Posted May 9, 2013 Moderators Share Posted May 9, 2013 michaelslamet, Delighted that we could help. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted May 9, 2013 Share Posted May 9, 2013 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 GudeHow 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 More sharing options...
Moderators Melba23 Posted May 9, 2013 Moderators Share Posted May 9, 2013 (edited) 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 WEndDoes it actually work for you? M23Edit: Brain fart on my part - see below. Edited May 9, 2013 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
michaelslamet Posted May 9, 2013 Author Share Posted May 9, 2013 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 More sharing options...
michaelslamet Posted May 9, 2013 Author Share Posted May 9, 2013 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 More sharing options...
Moderators Melba23 Posted May 9, 2013 Moderators Share Posted May 9, 2013 michaelslamet, Obvious when you think about it! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
michaelslamet Posted May 9, 2013 Author Share Posted May 9, 2013 Hi Melba, I can check it using "If" but I wonder is there any shorter and quicker way, for example using defined style Link to comment Share on other sites More sharing options...
michaelslamet Posted May 9, 2013 Author Share Posted May 9, 2013 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 9, 2013 Moderators Share Posted May 9, 2013 michaelslamet, I understood you perfectly. I have an idea and I am trying to get it to work - give me a little while. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted May 9, 2013 Share Posted May 9, 2013 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 GudeHow 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 More sharing options...
michaelslamet Posted May 9, 2013 Author Share Posted May 9, 2013 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 Maybe Melba will come out with another ideas Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 9, 2013 Moderators Share Posted May 9, 2013 (edited) 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: expandcollapse popup#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! Edited May 9, 2013 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
michaelslamet Posted May 9, 2013 Author Share Posted May 9, 2013 Melba, Yes, clear as always and even more clear with code/example Thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now