Jump to content
Sign in to follow this  

[Solved] _GUICtrlListView_SetColumnWidth Trouble

Recommended Posts



I've been struggling with this single problem for 5 or 6 hours now, and I need help. I'm attempting to create a GUI that will remember the widths of columns in its ListView. Values are saved to file on exit, and read when the program runs. It's reading the values in correctly. The problem is when I use _GUICtrlListView_SetColumnWidth to set the column width, the columns are drastically larger than the settings file indicated. I have no idea what's causing this. Any help will be appreciated. If it matters, I am running the most recent AutoIt and SciTE. I have Win7 64-bit, and I've tried both x86 and x64 modes (no dice). Ultimately, I want the user to be able to drag columns wider or narrower (or to hide them) and have it keep those settings. I've commented out the code that sets the column width (see the Initialize() function). Can anyone tell me what I'm doing wrong?

Here's the .au3 file:

Global $hGUI, $hListView
Global Const $iniPath = @ScriptDir & '\test.ini'
Global Const $ver = "test"

Func Initialize()
; Create the GUI
$hGUI = GUICreate($ver, 400, 440)
$hListView = GUICtrlCreateListView("String|URL 1|URL 2|date|number 1|number 2", 5, 5, 390, 390, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
; Parse the ini file
Local $i, $iniFile, $record, $settings
If FileExists($iniPath) Then
  $iniFile = FileOpen($iniPath, 0)
  $record = FileReadLine($iniFile)
  If $record <> $ver Then
   MsgBox(16, "Fatal Error", "test.ini is invalid. Repair or delete to continue." & @LF & "Expected line 1: " & $ver & @LF & "Actual line 1: " & $record)
   Exit 1
  $settings = StringSplit(FileReadLine($iniFile), '|', 3)
  $record = FileReadLine($iniFile)
  While $record <> ""
   If StringInStr($record, '|', 1, 5) == 0 Or StringInStr($record, '|', 1, 6) > 0 Then
    MsgBox(16, "Fatal Error", "test.ini is invalid. Repair or delete to continue." & @LF & "Expected: 5 instances of | per line" & @LF & "Error on line " & String(_GUICtrlListView_GetItemCount($hListView) + 1) & ':' & @LF & $record)
    Exit 1
   GUICtrlCreateListViewItem($record, $hListView)
   $record = FileReadLine($iniFile)
  ; GUI Settings
;~   _GUICtrlListView_SetColumnWidth($hListView, 0, $settings[0])
;~   _GUICtrlListView_SetColumnWidth($hListView, 1, $settings[1])
;~   _GUICtrlListView_SetColumnWidth($hListView, 2, $settings[2])
;~   _GUICtrlListView_SetColumnWidth($hListView, 3, $settings[3])
;~   _GUICtrlListView_SetColumnWidth($hListView, 4, $settings[4])
;~   _GUICtrlListView_SetColumnWidth($hListView, 5, $settings[5])
GUISetState(@SW_SHOW, $hGUI)

Func Main()
; Run the GUI
    While 1
  Switch GUIGetMsg()

Func SaveAndExit()
; Save ini file and exit
Local $i, $iniFile, $settings
$settings = _GUICtrlListView_GetColumnWidth($hListView, 0) & '|' & _
    _GUICtrlListView_GetColumnWidth($hListView, 1) & '|' & _
    _GUICtrlListView_GetColumnWidth($hListView, 2) & '|' & _
    _GUICtrlListView_GetColumnWidth($hListView, 3) & '|' & _
    _GUICtrlListView_GetColumnWidth($hListView, 4) & '|' & _
    _GUICtrlListView_GetColumnWidth($hListView, 5)
$iniFile = FileOpen($iniPath, 2)
FileWriteLine($iniFile, $ver)
FileWriteLine($iniFile, $settings)
For $i = 0 To _GUICtrlListView_GetItemCount($hListView) - 1
  FileWriteLine($iniFile, _GUICtrlListView_GetItemTextString($hListView, $i))

Here's a sample settings file (test.ini):

AutoIt Script|http://www.autoitscript.com/site/autoit/|http://www.autoitscript.com/site/autoit/downloads/|4/10/2012|0|0

As an aside, I've also been playing with switching the order of rows. Currently, my only method of doing this is to read the values individually for each row and column and update them manually. Is there are better way to do that? It would be awesome if there was a way to change an index number and have the order automatically update. I'm not talking about automatically sorting rows. It's more like manually sorting rows.

Edited by Artisan

Share this post

Link to post
Share on other sites


Oh the joys of variants... Yep, #2 fixed it. And I was initially using IniRead/Write, but that got really cumbersome really quickly.

Anyway, thanks!

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