supersonic Posted January 29, 2010 Share Posted January 29, 2010 (edited) Hi! I'm trying to autosize ListViews using pixel width... When $LVSCW_AUTOSIZE < $LVSCW_AUTOSIZE_USEHEADER then the column is sized by column header width. When $LVSCW_AUTOSIZE > $LVSCW_AUTOSIZE_USEHEADER then the column is sized by item text width. The little function I wrote works pretty well, but it is rather slow (when using large ListViews)... Is there a way to improve performance? Func _GUICtrlListView_SetColumnWidth2($hWnd, $iVal = 0) Local $vTmp = _GUICtrlListView_GetColumnCount($hWnd) If $iVal > $vTmp Then $iVal = $vTmp ; <...> _GUICtrlListView_SetColumnWidth($hWnd, $iVal, $LVSCW_AUTOSIZE) Local $aTmp1 = _GUICtrlListView_GetColumn($hWnd, $iVal) _GUICtrlListView_SetColumnWidth($hWnd, $iVal, $LVSCW_AUTOSIZE_USEHEADER) Local $aTmp2 = _GUICtrlListView_GetColumn($hWnd, $iVal) ; <...> If $aTmp1[4] < $aTmp2[4] Then _GUICtrlListView_SetColumnWidth($hWnd, $iVal, $LVSCW_AUTOSIZE_USEHEADER) If $aTmp1[4] > $aTmp2[4] Then _GUICtrlListView_SetColumnWidth($hWnd, $iVal, $LVSCW_AUTOSIZE) EndFunc Greets, -supersonic. Edited January 29, 2010 by supersonic Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 29, 2010 Moderators Share Posted January 29, 2010 (edited) supersonic, This is how I would do it: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListViewConstants.au3> Global $aData[5] = ["1|1|1", "2|2222222222222|2", "33333333|3333|33333333333333", "4|444444444444444444444444444|4", "5|5|5"] Global $aRet, $iMaxElement = 0, $iGUI_Width = 500 ; Create GUI Global $hGUI = GUICreate("Test", $iGUI_Width, 500) ; Create List View Global $hListView = GUICtrlCreateListView(" | | ", 10, 10, 480, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FULLROWSELECT, $WS_EX_CLIENTEDGE)) ; Add data For $i = 0 To 4 GUICtrlCreateListViewItem($aData[$i], $hListView) Next ; Determine ListView width $iLV_Width = 0 For $i = 0 To 2 GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, $i, $LVSCW_AUTOSIZE) $iLV_Width += GUICtrlSendMsg($hListView, $LVM_GETCOLUMNWIDTH, $i, 0) Next ; resize ListView and GUI ControlMove($hGUI, "", $hListView, 10, 10, $iLV_Width + 10, 480) ; Add 10 becasue of internal borders WinMove($hGUI, "", Default, Default, $iLV_Width + 30) ; Add 30 for internal and external borders GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd It gets a bit more complex if there are too many lines to fit the GUI because the vertical scroll bar will appear. I will try and work on that this afternoon. I hope we are on the right track. M23 Edit: Tpying! Edited January 29, 2010 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...
Moderators Melba23 Posted January 29, 2010 Moderators Share Posted January 29, 2010 supersonic, This version will automatically increase the width of the ListView if a scroll bar is needed: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListViewConstants.au3> #Include <GuiListView.au3> Global $iColumns = 3, $sHeader = " | | ", $iScroll_Allowance = 0 Global $aData[5] = ["1|1|1", "2|2222222222222|2", "33333333|3333|33333333333333", "4|444444444444444444444444444|4", "5|5|5"] Global $iGUI_Width = 500, $iGUI_Height = 200 ; Create GUI at initial size Global $hGUI = GUICreate("Test", $iGUI_Width, $iGUI_Height) ; Create List View at initial size Global $hListView = GUICtrlCreateListView($sHeader, 10, 10, $iGUI_Width - 20, $iGUI_Height - 20, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FULLROWSELECT, $WS_EX_CLIENTEDGE)) ; Add data For $i = 0 To UBound($aData) - 1 GUICtrlCreateListViewItem($aData[$i], $hListView) Next ; Scroll down to ensure final item visible _GUICtrlListView_EnsureVisible($hListView, UBound($aData) - 1) ; Check top index - if not 0 then we have a scroll bar so increase ListView width If _GUICtrlListView_GetTopIndex($hListView) > 0 Then $iScroll_Allowance = 17 EndIf ; Scroll to top again _GUICtrlListView_EnsureVisible($hListView, 0) ; Determine ListView width $iLV_Width = $iScroll_Allowance For $i = 0 To $iColumns - 1 GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, $i, $LVSCW_AUTOSIZE) $iLV_Width += GUICtrlSendMsg($hListView, $LVM_GETCOLUMNWIDTH, $i, 0) Next ; Resize ListView and GUI to fit data ControlMove($hGUI, "", $hListView, 10, 10, $iLV_Width + 10, $iGUI_Height - 20) ; Add 10 for internal ListView borders WinMove($hGUI, "", Default, Default, $iLV_Width + 30) ; Add 30 for internal ListView and external GUI borders GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Are we getting there? 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...
supersonic Posted January 29, 2010 Author Share Posted January 29, 2010 (edited) Melba, thank you, good point to start with... But how can I autosize a column to make the whole header text visible (see attachment)? In my ListViews the header text is often larger than the itmes themselves... My function works well here, but it's rather slow when using rather large LVs ($array[300][50])... Edited January 29, 2010 by supersonic Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 29, 2010 Moderators Share Posted January 29, 2010 supersonic,Would Sir like fries with this? expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListViewConstants.au3> #Include <GuiListView.au3> Global $iColumns = 3, $sHeader = "This header is longer than the items| | ", $iScroll_Allowance = 0 Global $aData[5] = ["1|1|1", "2|2222222222222|2", "33333333|3333|33333333333333", "4|444444444444444444444444444|4", "5|5|5"] Global $iGUI_Width = 500, $iGUI_Height = 200 ; Create GUI at initial size Global $hGUI = GUICreate("Test", $iGUI_Width, $iGUI_Height) ; Create List View at initial size Global $hListView = GUICtrlCreateListView($sHeader, 10, 10, $iGUI_Width - 20, $iGUI_Height - 20, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FULLROWSELECT, $WS_EX_CLIENTEDGE)) ; Add data For $i = 0 To UBound($aData) - 1 GUICtrlCreateListViewItem($aData[$i], $hListView) Next ; Scroll down to ensure final item visible _GUICtrlListView_EnsureVisible($hListView, UBound($aData) - 1) ; Check top index - if not 0 then we have a scroll bar so increase ListView width If _GUICtrlListView_GetTopIndex($hListView) > 0 Then $iScroll_Allowance = 17 EndIf ; Scroll to top again _GUICtrlListView_EnsureVisible($hListView, 0) ; Determine ListView width $iLV_Width = $iScroll_Allowance For $i = 0 To $iColumns - 1 ; Size column to fit header _GUICtrlListView_SetColumnWidth($hListView, $i, $LVSCW_AUTOSIZE_USEHEADER) $iHeader_Width = _GUICtrlListView_GetColumnWidth($hListView, $i) ; Now size column to fit data _GUICtrlListView_SetColumnWidth($hListView, $i, $LVSCW_AUTOSIZE) $iData_Width = _GUICtrlListView_GetColumnWidth($hListView, $i) ; If header is wider, reset width If $iHeader_Width > $iData_Width Then _GUICtrlListView_SetColumnWidth($hListView, $i, $iHeader_Width) $iLV_Width += $iHeader_Width Else $iLV_Width += $iData_Width EndIf Next ; Resize ListView and GUI to fit data ControlMove($hGUI, "", $hListView, 10, 10, $iLV_Width + 10, $iGUI_Height - 20) ; Add 10 for internal ListView borders WinMove($hGUI, "", Default, Default, $iLV_Width + 30) ; Add 30 for internal ListView and external GUI borders GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndI have used _GUICtrlListView functions when we set the column width to make it easier to follow - all they do is wrap the GUICtrlSendMsg commands we used before. M23 pixelsearch and maniootek 2 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...
supersonic Posted January 29, 2010 Author Share Posted January 29, 2010 Melba, cool! I will adopt this, thank you! Link to comment Share on other sites More sharing options...
hench Posted October 14, 2010 Share Posted October 14, 2010 Wow, thanks Melba, I really like your Autoit Programming style, always top-notch clean... and helpful! Which is great for the community. Keep it goin' eh!! hench maniootek 1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 14, 2010 Moderators Share Posted October 14, 2010 hench, Thank you for taking the time to say so. Merci pour avoir pris le temps de le dire*. M23 *Je sais comment vous Québecois insistent que tout le monde parle en français! 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...
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