NiVZ Posted May 6, 2010 Share Posted May 6, 2010 (edited) Ive got a gui with a standard GuiCtrlCreateListView and i hide a column by setting width to zero or using the hide column function but it reappears when i add a new item to the listview using GuiCtrlCreateListViewItem. It works correctly if i do this to the first column but not for any other. What is the correct way to do this so the column is never shown? Thanks, NiVZ Edited May 6, 2010 by NiVZ Link to comment Share on other sites More sharing options...
Fire Posted May 6, 2010 Share Posted May 6, 2010 Hi NiVZ. I think about this way: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #Include <GuiListView.au3> $Form1 = GUICreate("", 633, 476, 192, 124) $ListView1 = GUICtrlCreateListView("Column 1" & "|" & "Column 2", 88, 72, 433, 241) $Button1 = GUICtrlCreateButton("Show Col 2", 96, 376, 129, 33, $WS_GROUP) $Button2 = GUICtrlCreateButton("Hide Col 2", 392, 376, 129, 33, $WS_GROUP) $contextmenu=GUICtrlCreateContextMenu($ListView1) $contextmenuitem1=GUICtrlCreateMenuItem("Show Col 2",$contextmenu) $hidecolumn2=GUICtrlCreateMenuItem("Hide Col 2",$contextmenu) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1,$contextmenuitem1 _GUICtrlListView_DeleteAllItems($ListView1) For $i=0 To 100 GUICtrlCreateListViewItem($i & "|" & $i , $ListView1) Next Case $Button2,$hidecolumn2 _GUICtrlListView_DeleteAllItems($ListView1) For $i=0 To 15 GUICtrlCreateListViewItem($i & "|" , $ListView1) Next EndSwitch WEnd [size="5"] [/size] Link to comment Share on other sites More sharing options...
NiVZ Posted May 7, 2010 Author Share Posted May 7, 2010 Hi NiVZ. I think about this way: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #Include <GuiListView.au3> $Form1 = GUICreate("", 633, 476, 192, 124) $ListView1 = GUICtrlCreateListView("Column 1" & "|" & "Column 2", 88, 72, 433, 241) $Button1 = GUICtrlCreateButton("Show Col 2", 96, 376, 129, 33, $WS_GROUP) $Button2 = GUICtrlCreateButton("Hide Col 2", 392, 376, 129, 33, $WS_GROUP) $contextmenu=GUICtrlCreateContextMenu($ListView1) $contextmenuitem1=GUICtrlCreateMenuItem("Show Col 2",$contextmenu) $hidecolumn2=GUICtrlCreateMenuItem("Hide Col 2",$contextmenu) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1,$contextmenuitem1 _GUICtrlListView_DeleteAllItems($ListView1) For $i=0 To 100 GUICtrlCreateListViewItem($i & "|" & $i , $ListView1) Next Case $Button2,$hidecolumn2 _GUICtrlListView_DeleteAllItems($ListView1) For $i=0 To 15 GUICtrlCreateListViewItem($i & "|" , $ListView1) Next EndSwitch WEnd Thanks, but not quite what I was after - I still want to have data in the column but just not display it. I had hoped by setting column width to zero at the start (or using the hide column function) that it would never show the column ever, but it seems that using GUICtrlCreateListViewItem automatically shows the column by auto-adjusting the width. I have a way round it now though - going to stop GUI repainting using GUISetState(@SW_LOCK), setup all the data and hide the columns and then allow re-painting by using GUISetState(@SW_UNLOCK). Unless anyone has any better suggestions. Thanks, NiVZ Link to comment Share on other sites More sharing options...
DW1 Posted May 7, 2010 Share Posted May 7, 2010 (edited) You can use _GUICtrlListView_BeginUpdate() and _GUICtrlListView_EndUpdate()That way you do not have to lock the entire GUI... just the control itself.expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Global $Gx = 101, $Add = 150, $HideCol = 0 $Form1 = GUICreate("", 633, 476, 192, 124) $ListView1 = GUICtrlCreateListView("Column 1" & "|" & "Column 2", 88, 72, 433, 241) $Button1 = GUICtrlCreateButton("Show Col 2", 96, 376, 129, 33, $WS_GROUP) $Button2 = GUICtrlCreateButton("Hide Col 2", 392, 376, 129, 33, $WS_GROUP) $Button3 = GUICtrlCreateButton("Add " & $Add & " Items", 245, 376, 129, 33, $WS_GROUP) $contextmenu = GUICtrlCreateContextMenu($ListView1) $contextmenuitem1 = GUICtrlCreateMenuItem("Show Col 2", $contextmenu) $hidecolumn2 = GUICtrlCreateMenuItem("Hide Col 2", $contextmenu) $additem = GUICtrlCreateMenuItem("Add " & $Add & " Items", $contextmenu) For $i = 0 To 100 GUICtrlCreateListViewItem($i & "|" & $i, $ListView1) Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1, $contextmenuitem1 $HideCol = 0 _GUICtrlListView_SetColumnWidth($ListView1, 1, $LVSCW_AUTOSIZE_USEHEADER) Case $Button2, $hidecolumn2 $HideCol = 1 _GUICtrlListView_SetColumnWidth($ListView1, 1, 0) Case $Button3, $additem _GUICtrlListView_BeginUpdate($ListView1) For $i = $Gx To $Gx + $Add - 1 GUICtrlCreateListViewItem($i & "|" & $i, $ListView1) Next $Gx += $Add If $HideCol = 1 Then _GUICtrlListView_SetColumnWidth($ListView1, 1, 0) Else _GUICtrlListView_SetColumnWidth($ListView1, 1, $LVSCW_AUTOSIZE_USEHEADER) EndIf _GUICtrlListView_EndUpdate($ListView1) EndSwitch WEnd Edited May 7, 2010 by danwilli AutoIt3 Online Help 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