Jump to content
Sign in to follow this  
NiVZ

Hide ListView Column

Recommended Posts

NiVZ

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 by NiVZ

Share this post


Link to post
Share on other sites
Fire

Hi NiVZ.

I think about this way:

#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]

Share this post


Link to post
Share on other sites
NiVZ

Hi NiVZ.

I think about this way:

#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

Share this post


Link to post
Share on other sites
DW1

You can use _GUICtrlListView_BeginUpdate() and _GUICtrlListView_EndUpdate()

That way you do not have to lock the entire GUI... just the control itself.

#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 by danwilli

Share this post


Link to post
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
Sign in to follow this  

×