Sign in to follow this  
Followers 0
Garp99HasSpoken

Why is ListView handling so complicated?

14 posts in this topic

Why is ListView handling so complicated?

There seems to be so much involved in getting things working in a new program that I see as standard functionality,

yet we have to start over from scratch to make things work.

Simple expectations like:

- clicking on column header will sort up/down the list automatically

- setting the initial item in the list as highlighted/current

- pressing ENTER or double-clicking to EDIT that item (also from MENU -- >Edit item)

- pressing DEL to delete that item (or (MENU --> Delete Item)

- adding new item will sort the list automatically with this new item as current

- handling more than one ListView at a time

- using the UP/DOWN arrow keys automatically in a ListView

- using the WM_NOTIFY mechanism without all the _DebugPrint() from the HELP file

I am unable to find any real-world examples of how this is done in Wiki, Example scripts, the forum, etc

Are there any that I dimply haven't found?

Share this post


Link to post
Share on other sites



You're going to have to do it in your code because that's how listviews work. It's a Windows thing, and the listview UDF makes it very easy once you get the hang of it.

BTW, there is 0 reason to get any debug output unless you turn it on. The default is off so you must have coded it wrong


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 Gude
How 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

Share this post


Link to post
Share on other sites

I copy/pasted the example from the help and debug output is on.

Once thing I find frustrating now is that using Func WM_Notify() means that the current list item is no longer selected, UP/DOWN keys no longer work,

using CLICK or DBL-CLICK does not highlight current selection, and pressing ENTER/RETURN key is not registering as having been pressed.

From the HELP, I got a working SORT with arrows but not for a DATE column (ex: February 15, 2013)

I would love to learn from a real-world program that uses ListView with a menu and form, such as a db for a customer form with ADD/EDIT/DELETE etc.

Share this post


Link to post
Share on other sites

What example did you use? Post the script that's not working as expected and let us know what you're trying to do with it.


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 Gude
How 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

Share this post


Link to post
Share on other sites

Ok, Here's a subset of my code that you can compile/run to see the problem (I removed irrelevant stuff and hard-coded test data).

Problems are as listed in my previous post above.

;Autoit Options
; #NoTrayIcon ;No Tray Icon
Opt("GUIOnEventMode", 1)
Opt("WinTextMatchMode", 1) ;1=complete, 2=quick
Opt("WinTitleMatchMode", 3) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("GUICloseOnESC", 0) ;1=ESC closes, 0=ESC won't close
Opt("GUIResizeMode", 802)

#Include <String.au3>
#include <Date.au3>
#Include <WinAPI.au3>
#include <File.au3>
#include <GuiTab.au3>
;#include <GDIPlus.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiScrollBars.au3>
#include <GuiStatusBar.au3>
#include <GuiToolbar.au3>

; Constants includes
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <ToolbarConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

; Tab groups
Global Const $L_VOLUNTEERS = " Volunteers "
Global Const $L_VOLUNTEER = "Volunteer"
Global Const $L_EVENTS = " Events "
Global Const $L_EVENT = "Event"
Global Const $L_FORMS = " Forms "
Global Const $L_FORM = "Form"
Global Const $L_LABELS = " Labels "
Global Const $L_LABEL = "Label"
Global Const $L_GLOBAL = "Global Options"

; Menus
Global Const $M_FILE = "&File"
Global Const $M_EDIT = "&Edit"
Global Const $M_EVENT = "Even&t"
Global Const $M_VOLUNTEER = "&Volunteer"
Global Const $M_OPTIONS = "&Go To..."

; Buttons
Global Const $L_OK = "&OK"
Global Const $L_DONE = "&Done"
Global Const $L_CANCEL = "&Cancel"
Global Const $L_ADD = "<< &Add"
Global Const $L_REMOVE = "&Remove >>"

; Prompts
Global Const $L_AREYOUSURE = "Are You Sure?"
Global Const $L_CANCELEXIT = "Cancel all changes and exit?"

; Tab items
Global Const $T_Event = 0
Global Const $T_Volunteer = 1
Global Const $T_Forms = 2
Global Const $T_Labels = 3

;Versions Info
Global $ProgName = "Volunteer Coordinator"
Global $VersionBuild = "20130213" ;YEAR|MON|DAY
Global $ProgVersion = "0.1"
GLOBAL $AboutVersion = "2013.02.13 (" & $ProgVersion & ")"

Global $ProgWidth =1024, $ProgHeight = 720

Local $sWidth = 400, $sHeight = 350
Local $hToolbar = 40, $hStatus = 40, $hTabs = $hToolbar+30, $hLists = ($ProgHeight - $hTabs - $hStatus - $hToolbar)

#Region ### START Koda GUI section ### Form=R:\AutoIt Examples\koda_2008-09-03\Forms\VolunteerCoordinator.kxf
Global $MainForm = GUICreate($ProgName, $ProgWidth, $ProgHeight, (@DesktopWidth - $ProgWidth) / 2, (@DesktopHeight - $ProgHeight) / 2, $WS_SIZEBOX + $WS_SYSMENU )
GUISetState(@SW_HIDE)
GUISetBkColor(0xA6CAF0)
GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "")
GUISetOnEvent($GUI_EVENT_RESTORE, "")
Global $TabVol = GUICtrlCreateTab(1, $hTabs-$hToolbar, $ProgWidth-2, $hToolbar, $TCS_TABS)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)

Global $TabSheetEvents = GUICtrlCreateTabItem($L_EVENTS)
Global $ListViewEvents = GUICtrlCreateListView( _
"Date |Type |From |To ", _
2, $hTabs, 815, $hLists-12, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $LVS_SORTDESCENDING)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "ListViewEventsClick")
Global $ListEventsVol = GUICtrlCreateList("", 819, $hTabs, 202, 618)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "ListEventsVolClick")
_GUICtrlListView_SetColumnWidth($ListViewEvents, 0, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewEvents, 1, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_RegisterSortCallBack(-1, True, True)
EventFullList()

Global $TabSheetVolunteers = GUICtrlCreateTabItem($L_VOLUNTEERS)
Global $ListViewVolunteers = GUICtrlCreateListView( _
"Name |Type |Home |Work |Cell |Address |City |Prov|Postal|Notes ", _
2, $hTabs, $ProgWidth-4, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $LVS_SORTASCENDING)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "ListViewVolunteersClick")
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 0, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 1, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 2, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 3, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 4, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 6, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 9, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_RegisterSortCallBack(-1, False, True)
VolunteerFullList()

Global $TabSheetForms = GUICtrlCreateTabItem($L_FORMS)
Global $ListViewForms = GUICtrlCreateListView( _
"Name |Style ", _
2, $hTabs, 600, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $LVS_SORTASCENDING)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "ListViewFormsClick")

Global $TabSheetLabels = GUICtrlCreateTabItem($L_LABELS)
GUICtrlSetState(-1,$GUI_SHOW)
Global $ListViewLabels = GUICtrlCreateListView( _
"Name |Style ", _
2, $hTabs, 600, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $LVS_SORTASCENDING)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetState($TabSheetEvents, $GUI_SHOW)
;GUICtrlSetOnEvent(-1, "TabVolChange")

GUICtrlCreateTabItem("") ;end of tabs
sleep(500)
_GUICtrlTab_SetCurFocus($TabVol, $T_Event)

;==> FILE menu
Local $MenuFile = GUICtrlCreateMenu($M_FILE)
Local $MenuFileOpen = GUICtrlCreateMenuItem("Open..." & @tab & "Ctrl+O", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileOpenClick")
Local $MenuFileSave = GUICtrlCreateMenuItem("Save" & @tab & "Ctrl+S", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileSaveClick")
Local $MenuFileSaveAs = GUICtrlCreateMenuItem("Save As..." & @tab & "F3", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileSaveAsClick")
Local $MenuFilePrint = GUICtrlCreateMenuItem("Print..." & @tab & "Ctrl+P", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFilePrintClick")
Local $MenuFileExit = GUICtrlCreateMenuItem("Exit" & @tab & "Ctrl+E", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileExitClick")

;==> EDIT menu
Local $MenuEdit = GUICtrlCreateMenu($M_EDIT)
;Local $MenuEditCut = GUICtrlCreateMenuItem("Cut" & @tab & "Ctrl+X", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditCutClick")
;Local $MenuEditCopy = GUICtrlCreateMenuItem("Copy" & @tab & "Ctrl+C", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditCopyClick")
;Local $MenuEditPaste = GUICtrlCreateMenuItem("Paste" & @tab & "Ctrl+V", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditPasteClick")
Local $MenuEditListItem = GUICtrlCreateMenuItem("Edit List Item" & @tab & "F2", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditListItemClick")
Local $MenuGlobalOptions = GUICtrlCreateMenuItem($L_GLOBAL & @tab & "F4", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuGlobalOptionsClick")

;==> EVENT menu
Local $MenuEvent = GUICtrlCreateMenu($M_EVENT)
Local $MenuEventAdd = GUICtrlCreateMenuItem("Add " & $L_EVENT & @tab & "F9", $MenuEvent)
;GUICtrlSetOnEvent(-1, "MenuEventAddClick")
Local $MenuEventEdit = GUICtrlCreateMenuItem("Edit " & $L_EVENT & @tab & "F10", $MenuEvent)
;GUICtrlSetOnEvent(-1, "MenuEventEditClick")
Local $MenuEventDelete = GUICtrlCreateMenuItem("Delete " & $L_EVENT & @tab & "", $MenuEvent)
;GUICtrlSetOnEvent(-1, "MenuEventDeleteClick")

;==> VOLUNTEER menu
Local $MenuVolunteer = GUICtrlCreateMenu($M_VOLUNTEER)
Local $MenuVolunteerAdd = GUICtrlCreateMenuItem("Add " & $L_VOLUNTEER & @tab & "F11", $MenuVolunteer)
;GUICtrlSetOnEvent(-1, "MenuVolunteerAddClick")
Local $MenuVolunteerEdit = GUICtrlCreateMenuItem("Edit " & $L_VOLUNTEER & @tab & "F12", $MenuVolunteer)
;GUICtrlSetOnEvent(-1, "MenuVolunteerEditClick")
Local $MenuVolunteerDelete = GUICtrlCreateMenuItem("Delete " & $L_VOLUNTEER & @tab & "", $MenuVolunteer)
;GUICtrlSetOnEvent(-1, "MenuVolunteerDeleteClick")

;==> OPTIONS menu
Local $MenuOptions = GUICtrlCreateMenu($M_OPTIONS)
Local $MenuEventDates = GUICtrlCreateMenuItem($L_EVENT & " Dates" & @tab & "F5", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuEventDatesClick")
Local $MenuVolList = GUICtrlCreateMenuItem($L_VOLUNTEER & " List" & @tab & "F6", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuVolListClick")
Local $MenuForms = GUICtrlCreateMenuItem("Forms" & @tab & "F7", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuFormsClick")
Local $MenuLabels = GUICtrlCreateMenuItem("Labels" & @tab & "F8", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuLabelsClick")

;==> HELP menu
Local $MenuHelp = GUICtrlCreateMenu("Help")
;GUICtrlSetOnEvent(-1, "MenuHelpClick")
Local $MenuHelpAbout = GUICtrlCreateMenuItem("About" & @tab & "F1", $MenuHelp)
;GUICtrlSetOnEvent(-1, "MenuHelpAboutClick")


; MENU hotkeys
;Local $MainForm_AccelTable[3][2] = [ ["^x", $MenuEditCut],["^c", $MenuEditCopy],["^v", $MenuEditPaste] ]
Local $MainForm_AccelTable[22][2] = [ _
["^!f", $MenuFile],["^o", $MenuFileOpen],["^s", $MenuFileSave],["{F3}", $MenuFileSaveAs],["^p", $MenuFilePrint], ["^e", $MenuFileExit], _
["^!e", $MenuEdit],["{F2}", $MenuEditListItem],["{F4}", $MenuGlobalOptions], _
["^!t", $MenuEvent],["{F9}", $MenuEventAdd],["{F10}", $MenuEventEdit], _
["^!v", $MenuVolunteer],["{F11}", $MenuVolunteerAdd],["{F12}", $MenuVolunteerEdit], _
["^!g", $MenuOptions],["{F5}", $MenuEventDates],["{F6}", $MenuVolList],["{F7}", $MenuForms],["{F8}", $MenuLabels], _
["^!h", $MenuHelp],["{F1}", $MenuHelpAbout] _
]
GUISetAccelerators($MainForm_AccelTable, $MainForm)


Global $ToolBar = _GUICtrlToolbar_Create($MainForm, 0)
_GUICtrlToolbar_AddButton($ToolBar, 0, 0)
_GUICtrlToolbar_AddButton($ToolBar, 0, 1)
_GUICtrlToolbar_AddButton($ToolBar, 0, 2)
_GUICtrlToolbar_AddButton($ToolBar, 0, 3)
_GUICtrlToolbar_AddButton($ToolBar, 0, 4)
_GUICtrlToolbar_AddButton($ToolBar, 0, 5)

Global $StatusBar = _GUICtrlStatusBar_Create($MainForm)
_GUICtrlStatusBar_SetSimple($StatusBar)
_GUICtrlStatusBar_SetText($StatusBar, "Simple status bar window text goes here.")
_GUICtrlStatusBar_SetMinHeight($StatusBar, $hStatus)

GUISetFont(10, 400, 0, "MS Sans Serif", $MainForm)
GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose")
;GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, '_PRIMARYdown')
GUISetOnEvent($GUI_EVENT_RESTORE, "")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "")
GUISetOnEvent($GUI_EVENT_RESIZED, "")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

#EndRegion ### END Koda GUI section ###

GUISwitch($MainForm)
GUISetState(@SW_SHOW)

;GUISetState(@SW_SHOW, $MainForm)
While 1
If (GUIGetMsg() = $GUI_EVENT_CLOSE) Then ExitLoop
WEnd

GUISetState(@SW_HIDE)
GUIDelete()
_GUICtrlListView_UnRegisterSortCallBack($ListViewEvents)
_GUICtrlListView_UnRegisterSortCallBack($ListViewVolunteers)
GUIRegisterMsg($WM_NOTIFY, "")
Exit

Func MainFormClose()
Exit
EndFunc ;==>MainFormClose

Func EventFullList()
GUICtrlCreateListViewItem("February 12, 2013|All Day|||_1_2_3", $ListViewEvents)
GUICtrlCreateListViewItem("February 13, 2013|AM|||_1_2", $ListViewEvents)
GUICtrlCreateListViewItem("February 13, 2013|PM|||_3_4", $ListViewEvents)
GUICtrlCreateListViewItem("February 15, 2013|From|11:00|18:00|_1_2_3_4", $ListViewEvents)
EndFunc ;==>EventFullList

Func VolunteerFullList()
GUICtrlCreateListViewItem("Dan Black|Parent|(514)345-6789|(514)345-9876|(608)345-1234|239 Temple Drive|Montreal|QC|H2N3M4|Coordinator", $ListViewVolunteers)
GUICtrlCreateListViewItem("Mary Pigment|Staff|(519)242-2020|(519)356-0176|(519)675-1201|21st Avenue|London|ON|J7S5M9|Principal", $ListViewVolunteers)
GUICtrlCreateListViewItem("Paul Green|Friend/Family|(514)349-6699|(514)349-5555|(514)698-9857|423 Happle / Apt 12|Montreal|QC|H2N5L1|", $ListViewVolunteers)
GUICtrlCreateListViewItem("Sheila Blue|Other|(514)345-7733|(514)655-4562|(608)345-1234|239 Temple Drive|Montreal|QC|H2N3M4|Coordinator", $ListViewVolunteers)
EndFunc ;==>VolunteerFullList

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo

$hWndListView1 = GUICtrlGetHandle($ListViewEvents)
If Not IsHWnd($ListViewEvents) Then $hWndListView1 = GUICtrlGetHandle($ListViewEvents)
$hWndListView2 = GUICtrlGetHandle($ListViewVolunteers)
If Not IsHWnd($ListViewVolunteers) Then $hWndListView2 = GUICtrlGetHandle($ListViewVolunteers)

$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")

Switch $hWndFrom
Case $hWndListView1
Switch $iCode
Case $LVN_COLUMNCLICK ; A column was clicked
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
; Kick off the sort callback
_GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
; No return value
Case $LVN_ITEMCHANGING ; An item is changing
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
Return True ; prevent the change
;Return False ; allow the change
Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You clicked on: " & $text)
; _GUICtrlListView_SetItemSelected($ListViewEvents, DllStructGetData($tInfo, "Index"))
Return $GUI_RUNDEFMSG
; No return value
Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You double-clicked on: " & $text)
Return $GUI_RUNDEFMSG
; DO EDIT HERE
; No return value
Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
$text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You hit ENTER on: " & $text)
EndSwitch

Case $hWndListView2
Switch $iCode
Case $LVN_COLUMNCLICK ; A column was clicked
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
; Kick off the sort callback
_GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
; No return value
Case $LVN_ITEMCHANGING ; An item is changing
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
Return True ; prevent the change
;Return False ; allow the change
Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You clicked on: " & $text)
; _GUICtrlListView_SetItemSelected($ListViewVolunteers, DllStructGetData($tInfo, "Index"))

;Return $GUI_RUNDEFMSG
; No return value
Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You double-clicked on: " & $text)
;Return $GUI_RUNDEFMSG
; No return value
; DO EDIT HERE
Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
$text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You hit ENTER on: " & $text)
; No return value
; DO EDIT HERE
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Share this post


Link to post
Share on other sites

A couple of problems that I see in the code, one is major, the others are minor.

First:

Global $TabSheetEvents = GUICtrlCreateTabItem($L_EVENTS)
Global $ListViewEvents = GUICtrlCreateListView( _
"Date |Type |From |To ", _
2, $hTabs, 815, $hLists-12, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $LVS_SORTDESCENDING)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "ListViewEventsClick")
Global $ListEventsVol = GUICtrlCreateList("", 819, $hTabs, 202, 618)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "ListEventsVolClick")
_GUICtrlListView_SetColumnWidth($ListViewEvents, 0, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewEvents, 1, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_RegisterSortCallBack(-1, True, True) ; <<<<<<<<<<<< this is referencing the $ListEventsVol listbox, not the listview
EventFullList() ; <<<<<<<< This should be before the SetColumnWidth function calls, otherwise you won't get full sized columns.

Second:

$hWndListView1 = GUICtrlGetHandle($ListViewEvents)
If Not IsHWnd($ListViewEvents) Then $hWndListView1 = GUICtrlGetHandle($ListViewEvents) ; <<<<<<<<<<< This is already set in the line above, it's redundant
$hWndListView2 = GUICtrlGetHandle($ListViewVolunteers)
If Not IsHWnd($ListViewVolunteers) Then $hWndListView2 = GUICtrlGetHandle($ListViewVolunteers) ; <<<<<<<<<<< This is already set in the line above, it's redundant

I'm not sure why the first listview won't sort though, it's setting the arrows to the headers correctly, but won't sort no matter what I've tried. I haven't been able to figure that part out yet.


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 Gude
How 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

Share this post


Link to post
Share on other sites

I made those minor changes and now sorting won't work on Volunteers even though I just moved lines around -- no changes to WM_Notify()

;Autoit Options
; #NoTrayIcon ;No Tray Icon
Opt("GUIOnEventMode", 1)
Opt("WinTextMatchMode", 1) ;1=complete, 2=quick
Opt("WinTitleMatchMode", 3) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("GUICloseOnESC", 0) ;1=ESC  closes, 0=ESC won't close
Opt("GUIResizeMode", 802)
; Opt("GUIResizeMode", 1)


#Include <String.au3>
#include <Date.au3>
#Include <WinAPI.au3>
#include <File.au3>
#include <GuiTab.au3>
;#include <GDIPlus.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiScrollBars.au3>
#include <GuiStatusBar.au3>
#include <GuiToolbar.au3>

; Constants includes
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <ToolbarConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

; Tab groups
Global Const $L_VOLUNTEERS =    "  Volunteers  "
Global Const $L_VOLUNTEER =    "Volunteer"
Global Const $L_EVENTS =        "  Events  "
Global Const $L_EVENT =        "Event"
Global Const $L_FORMS =        "  Forms  "
Global Const $L_FORM =        "Form"
Global Const $L_LABELS =        "  Labels  "
Global Const $L_LABEL =        "Label"
Global Const $L_GLOBAL =        "Global Options"

; Menus
Global Const $M_FILE =        "&File"
Global Const $M_EDIT =        "&Edit"
Global Const $M_EVENT =        "Even&t"
Global Const $M_VOLUNTEER =    "&Volunteer"
Global Const $M_OPTIONS =        "&Go To..."

; Buttons
Global Const $L_OK =            "&OK"
Global Const $L_DONE =        "&Done"
Global Const $L_CANCEL =        "&Cancel"
Global Const $L_ADD =            "<<   &Add"
Global Const $L_REMOVE =        "&Remove >>"

; Prompts
Global Const $L_AREYOUSURE =    "Are You Sure?"
Global Const $L_CANCELEXIT =    "Cancel all changes and exit?"

; Tab items
Global Const $T_Event =        0
Global Const $T_Volunteer =    1
Global Const $T_Forms =        2
Global Const $T_Labels =        3

;Versions Info
Global $ProgName = "Volunteer Coordinator"
Global $VersionBuild = "20130213"     ;YEAR|MON|DAY
Global $ProgVersion = "0.1"
GLOBAL $AboutVersion = "2013.02.13 (" & $ProgVersion & ")"

Global $ProgWidth =1024, $ProgHeight = 720

Local $sWidth = 400, $sHeight = 350
Local $hToolbar = 40, $hStatus = 40, $hTabs = $hToolbar+30, $hLists = ($ProgHeight - $hTabs - $hStatus - $hToolbar)

#Region ### START Koda GUI section ### Form=R:\AutoIt Examples\koda_2008-09-03\Forms\VolunteerCoordinator.kxf
Global $MainForm = GUICreate($ProgName, $ProgWidth, $ProgHeight, (@DesktopWidth - $ProgWidth) / 2, (@DesktopHeight - $ProgHeight) / 2, $WS_SIZEBOX + $WS_SYSMENU )
GUISetState(@SW_HIDE)
GUISetBkColor(0xA6CAF0)
GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "")
GUISetOnEvent($GUI_EVENT_RESTORE, "")
Global $TabVol = GUICtrlCreateTab(1, $hTabs-$hToolbar, $ProgWidth-2, $hToolbar, $TCS_TABS)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)

Global $TabSheetEvents = GUICtrlCreateTabItem($L_EVENTS)
Global $ListViewEvents = GUICtrlCreateListView( _
        "Date               |Type       |From   |To  ", _
        2, $hTabs, 815, $hLists-12, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $LVS_SORTDESCENDING)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
EventFullList()
;GUICtrlSetOnEvent(-1, "ListViewEventsClick")
_GUICtrlListView_SetColumnWidth(-1, 0, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth(-1, 1, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_RegisterSortCallBack(-1, True, True)

Global $ListEventsVol = GUICtrlCreateList("", 819, $hTabs, 202, 618)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "ListEventsVolClick")

Global $TabSheetVolunteers = GUICtrlCreateTabItem($L_VOLUNTEERS)
Global $ListViewVolunteers = GUICtrlCreateListView( _
        "Name               |Type        |Home      |Work       |Cell       |Address                 |City      |Prov|Postal|Notes                             ", _
        2, $hTabs, $ProgWidth-4, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $LVS_SORTASCENDING)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
VolunteerFullList()
;GUICtrlSetOnEvent(-1, "ListViewVolunteersClick")
_GUICtrlListView_SetColumnWidth(-1, 0, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth(-1, 1, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth(-1, 2, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth(-1, 3, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth(-1, 4, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth(-1, 6, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth(-1, 9, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_RegisterSortCallBack(-1, False, True)

Global $TabSheetForms = GUICtrlCreateTabItem($L_FORMS)
Global $ListViewForms = GUICtrlCreateListView( _
        "Name               |Style              ", _
        2, $hTabs, 600, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $LVS_SORTASCENDING)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "ListViewFormsClick")

Global $TabSheetLabels = GUICtrlCreateTabItem($L_LABELS)
GUICtrlSetState(-1,$GUI_SHOW)
Global $ListViewLabels = GUICtrlCreateListView( _
        "Name               |Style              ", _
        2, $hTabs, 600, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $LVS_SORTASCENDING)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;~ Sleep(1000)
;~ GUICtrlSetState($TabSheetVolunteers, $GUI_SHOW)
;~ Sleep(1000)
;~ GUICtrlSetState($TabSheetForms, $GUI_SHOW)
;~ Sleep(1000)
;~ GUICtrlSetState($TabSheetLabels, $GUI_SHOW)
;~ Sleep(1000)
GUICtrlSetState($TabSheetEvents, $GUI_SHOW)
;GUICtrlSetOnEvent(-1, "TabVolChange")

GUICtrlCreateTabItem("")    ;end of tabs
sleep(500)
_GUICtrlTab_SetCurFocus($TabVol, $T_Event)
; _GUICtrlTab_SetCurFocus($ListViewEvents, $T_Event)


;==> FILE menu
Local $MenuFile = GUICtrlCreateMenu($M_FILE)
Local $MenuFileOpen = GUICtrlCreateMenuItem("Open..." & @tab & "Ctrl+O", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileOpenClick")
Local $MenuFileSave = GUICtrlCreateMenuItem("Save" & @tab & "Ctrl+S", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileSaveClick")
Local $MenuFileSaveAs = GUICtrlCreateMenuItem("Save As..." & @tab &  "F3", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileSaveAsClick")
Local $MenuFilePrint = GUICtrlCreateMenuItem("Print..." & @tab & "Ctrl+P", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFilePrintClick")
Local $MenuFileExit = GUICtrlCreateMenuItem("Exit" & @tab & "Ctrl+E", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileExitClick")

;==> EDIT menu
Local $MenuEdit = GUICtrlCreateMenu($M_EDIT)
;Local $MenuEditCut = GUICtrlCreateMenuItem("Cut" & @tab & "Ctrl+X", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditCutClick")
;Local $MenuEditCopy = GUICtrlCreateMenuItem("Copy" & @tab & "Ctrl+C", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditCopyClick")
;Local $MenuEditPaste = GUICtrlCreateMenuItem("Paste" & @tab & "Ctrl+V", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditPasteClick")
Local $MenuEditListItem = GUICtrlCreateMenuItem("Edit List Item" & @tab & "F2", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditListItemClick")
Local $MenuGlobalOptions = GUICtrlCreateMenuItem($L_GLOBAL & @tab & "F4", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuGlobalOptionsClick")

;==> EVENT menu
Local $MenuEvent = GUICtrlCreateMenu($M_EVENT)
Local $MenuEventAdd = GUICtrlCreateMenuItem("Add " & $L_EVENT & @tab & "F9", $MenuEvent)
;GUICtrlSetOnEvent(-1, "MenuEventAddClick")
Local $MenuEventEdit = GUICtrlCreateMenuItem("Edit " & $L_EVENT & @tab & "F10", $MenuEvent)
;GUICtrlSetOnEvent(-1, "MenuEventEditClick")
Local $MenuEventDelete = GUICtrlCreateMenuItem("Delete " & $L_EVENT & @tab & "", $MenuEvent)
;GUICtrlSetOnEvent(-1, "MenuEventDeleteClick")

;==> VOLUNTEER menu
Local $MenuVolunteer = GUICtrlCreateMenu($M_VOLUNTEER)
Local $MenuVolunteerAdd = GUICtrlCreateMenuItem("Add " & $L_VOLUNTEER & @tab & "F11", $MenuVolunteer)
;GUICtrlSetOnEvent(-1, "MenuVolunteerAddClick")
Local $MenuVolunteerEdit = GUICtrlCreateMenuItem("Edit " & $L_VOLUNTEER & @tab & "F12", $MenuVolunteer)
;GUICtrlSetOnEvent(-1, "MenuVolunteerEditClick")
Local $MenuVolunteerDelete = GUICtrlCreateMenuItem("Delete " & $L_VOLUNTEER & @tab & "", $MenuVolunteer)
;GUICtrlSetOnEvent(-1, "MenuVolunteerDeleteClick")

;==> OPTIONS menu
Local $MenuOptions = GUICtrlCreateMenu($M_OPTIONS)
Local $MenuEventDates = GUICtrlCreateMenuItem($L_EVENT & " Dates" & @tab & "F5", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuEventDatesClick")
Local $MenuVolList = GUICtrlCreateMenuItem($L_VOLUNTEER & " List" & @tab & "F6", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuVolListClick")
Local $MenuForms = GUICtrlCreateMenuItem("Forms" & @tab & "F7", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuFormsClick")
Local $MenuLabels = GUICtrlCreateMenuItem("Labels" & @tab & "F8", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuLabelsClick")

;==> HELP menu
Local $MenuHelp = GUICtrlCreateMenu("Help")
;GUICtrlSetOnEvent(-1, "MenuHelpClick")
Local $MenuHelpAbout = GUICtrlCreateMenuItem("About" & @tab & "F1", $MenuHelp)
;GUICtrlSetOnEvent(-1, "MenuHelpAboutClick")


; MENU hotkeys
;Local $MainForm_AccelTable[3][2] = [ ["^x", $MenuEditCut],["^c", $MenuEditCopy],["^v", $MenuEditPaste] ]
Local $MainForm_AccelTable[22][2] = [ _
        ["^!f", $MenuFile],["^o", $MenuFileOpen],["^s", $MenuFileSave],["{F3}", $MenuFileSaveAs],["^p", $MenuFilePrint], ["^e", $MenuFileExit], _
        ["^!e", $MenuEdit],["{F2}", $MenuEditListItem],["{F4}", $MenuGlobalOptions], _
        ["^!t", $MenuEvent],["{F9}", $MenuEventAdd],["{F10}", $MenuEventEdit], _
        ["^!v", $MenuVolunteer],["{F11}", $MenuVolunteerAdd],["{F12}", $MenuVolunteerEdit],  _
        ["^!g", $MenuOptions],["{F5}", $MenuEventDates],["{F6}", $MenuVolList],["{F7}", $MenuForms],["{F8}", $MenuLabels], _
        ["^!h", $MenuHelp],["{F1}", $MenuHelpAbout] _
]
GUISetAccelerators($MainForm_AccelTable, $MainForm)


Global $ToolBar = _GUICtrlToolbar_Create($MainForm, 0)
_GUICtrlToolbar_AddButton($ToolBar, 0, 0)
_GUICtrlToolbar_AddButton($ToolBar, 0, 1)
_GUICtrlToolbar_AddButton($ToolBar, 0, 2)
_GUICtrlToolbar_AddButton($ToolBar, 0, 3)
_GUICtrlToolbar_AddButton($ToolBar, 0, 4)
_GUICtrlToolbar_AddButton($ToolBar, 0, 5)

Global $StatusBar = _GUICtrlStatusBar_Create($MainForm)
_GUICtrlStatusBar_SetSimple($StatusBar)
_GUICtrlStatusBar_SetText($StatusBar, "Simple status bar window text goes here.")
_GUICtrlStatusBar_SetMinHeight($StatusBar, $hStatus)

GUISetFont(10, 400, 0, "MS Sans Serif", $MainForm)
GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose")
;GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, '_PRIMARYdown')
GUISetOnEvent($GUI_EVENT_RESTORE, "")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "")
GUISetOnEvent($GUI_EVENT_RESIZED, "")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

#EndRegion ### END Koda GUI section ###

GUISwitch($MainForm)
GUISetState(@SW_SHOW)

;GUISetState(@SW_SHOW, $MainForm)
While 1
    If (GUIGetMsg() = $GUI_EVENT_CLOSE) Then ExitLoop
WEnd

GUISetState(@SW_HIDE)
GUIDelete()
_GUICtrlListView_UnRegisterSortCallBack($ListViewEvents)
_GUICtrlListView_UnRegisterSortCallBack($ListViewVolunteers)
GUIRegisterMsg($WM_NOTIFY, "")
Exit

Func MainFormClose()
  Exit
EndFunc   ;==>MainFormClose

Func EventFullList()
    GUICtrlCreateListViewItem("February 12, 2013|All Day|||_1_2_3", $ListViewEvents)
    GUICtrlCreateListViewItem("February 13, 2013|AM|||_1_2", $ListViewEvents)
    GUICtrlCreateListViewItem("February 13, 2013|PM|||_3_4", $ListViewEvents)
    GUICtrlCreateListViewItem("February 15, 2013|From|11:00|18:00|_1_2_3_4", $ListViewEvents)
EndFunc   ;==>EventFullList

Func VolunteerFullList()
    GUICtrlCreateListViewItem("Dan Black|Parent|(514)345-6789|(514)345-9876|(608)345-1234|239 Temple Drive|Montreal|QC|H2N3M4|Coordinator", $ListViewVolunteers)
    GUICtrlCreateListViewItem("Mary Pigment|Staff|(519)242-2020|(519)356-0176|(519)675-1201|21st Avenue|London|ON|J7S5M9|Principal", $ListViewVolunteers)
    GUICtrlCreateListViewItem("Paul Green|Friend/Family|(514)349-6699|(514)349-5555|(514)698-9857|423 Happle / Apt 12|Montreal|QC|H2N5L1|", $ListViewVolunteers)
    GUICtrlCreateListViewItem("Sheila Blue|Other|(514)345-7733|(514)655-4562|(608)345-1234|239 Temple Drive|Montreal|QC|H2N3M4|Coordinator", $ListViewVolunteers)
EndFunc   ;==>VolunteerFullList

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo

    $hWndListView1 = GUICtrlGetHandle($ListViewEvents)
    $hWndListView2 = GUICtrlGetHandle($ListViewVolunteers)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView1
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    ; Kick off the sort callback
                    _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
                    ; No return value
                Case $LVN_ITEMCHANGING ; An item is changing
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    Return True ; prevent the change
                    ;Return False ; allow the change
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index"))
                    _GUICtrlStatusBar_SetText($StatusBar, "You clicked on: " & $text)
;                    _GUICtrlListView_SetItemSelected($ListViewEvents, DllStructGetData($tInfo, "Index"))
Return $GUI_RUNDEFMSG
                    ; No return value
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index"))
                    _GUICtrlStatusBar_SetText($StatusBar, "You double-clicked on: " & $text)
Return $GUI_RUNDEFMSG
; DO EDIT HERE
                    ; No return value
                Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
                    $text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index"))
                    _GUICtrlStatusBar_SetText($StatusBar, "You hit ENTER on: " & $text)
            EndSwitch

        Case $hWndListView2
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    ; Kick off the sort callback
                    _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
                    ; No return value
                Case $LVN_ITEMCHANGING ; An item is changing
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    Return True ; prevent the change
                    ;Return False ; allow the change
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index"))
                    _GUICtrlStatusBar_SetText($StatusBar, "You clicked on: " & $text)
;                    _GUICtrlListView_SetItemSelected($ListViewVolunteers, DllStructGetData($tInfo, "Index"))

;Return $GUI_RUNDEFMSG
                    ; No return value
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index"))
                    _GUICtrlStatusBar_SetText($StatusBar, "You double-clicked on: " & $text)
;Return $GUI_RUNDEFMSG
                    ; No return value
; DO EDIT HERE
                Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
                    $text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index"))
                    _GUICtrlStatusBar_SetText($StatusBar, "You hit ENTER on: " & $text)
                    ; No return value
; DO EDIT HERE
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Share this post


Link to post
Share on other sites

Garp99HasSpoken,

If I may - I think you are trying to do too much in one go. I would hesitate to code a GUI as complex as the one you have from scratch - so I am not altogether surprised that you are having problems intgrating it all. And I absolutely agree that ListViews are complex little beasts - I had a devil of job with my GUIListViewEx UDF. ;)

Perhaps you should concentrate on getting to know and understand each element of the code before attempting to put it all together. Sounds wimpish I know, but it does help! :D

As to editing the contents of a ListView, I have posted several examples of that if you search the forum. If you cannot find anything, let me know and I will dig out some old scripts. But be warned: it is not simple - although I suspect you guessed that already! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I found the issue with the script, one of many, that caused this to not sort the first page.

You have the LV defined in the header with 4 columns, yet you're creating the items with 5 columns. This populates the listview with the first 4 items, but causes the function to return with an error and no control ID. Once you change the Events population of the LV to have 4 columns per item, it sorts correctly.

Also, instead of using -1 in the RegisterSortCallback routine, you should use the listview's control ID/Handle, because now that you've moved things around, the -1 no longer points to the listview.

This does nothing except keep the script alive. GUIGetMsg is ALWAYS returning 0 when you're using OnEvent mode.

While 1
    If (GUIGetMsg() = $GUI_EVENT_CLOSE) Then ExitLoop
WEnd

These are written wrong, you're putting a ListView style in the extended style parameter, which either does nothing or causes the listview to work completely differently than you'd expect depending upon what the value in the extended setting means.

Global $ListViewLabels = GUICtrlCreateListView( _

"Name |Style ", _

2, $hTabs, 600, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), $LVS_SORTASCENDING)

;this is an listview style in the extended style parameter, remove it or move it to the style parameter.


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 Gude
How 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

Share this post


Link to post
Share on other sites

If I may - I think you are trying to do too much in one go. I would hesitate to code a GUI as complex as the one you have from scratch - so I am not altogether surprised that you are having problems integrating it all. And I absolutely agree that ListViews are complex little beasts - I had a devil of job with my GUIListViewEx UDF.

It didn't seem like such a complicated idea before I started. ;)

I do have lots of programming experience but mostly server side and very little on the GUI side.

Perhaps you should concentrate on getting to know and understand each element of the code before attempting to put it all together. Sounds wimpish I know, but it does help!

That's why I do best with example code to work from.

As to editing the contents of a ListView, I have posted several examples of that if you search the forum. If you cannot find anything, let me know and I will dig out some old scripts. But be warned: it is not simple - although I suspect you guessed that already!

Not looking for inline editing but just the proper process for opening the form and getting the list to refresh once the user makes a change, and regaining focus on that line.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I found the issue with the script, one of many, that caused this to not sort the first page.

You have the LV defined in the header with 4 columns, yet you're creating the items with 5 columns. This populates the listview with the first 4 items, but causes the function to return with an error and no control ID. Once you change the Events population of the LV to have 4 columns per item, it sorts correctly.

I see the problem that you describe and will have to re-think how I pass the information around.

The idea was that I stored a list of volunteer ID numbers that worked that event, and that I would look up the IDs/keys to get the volunteer names and place them in the listbox on the right. Mainly because there are too many to list in a listview, so each event would show a different list on the right.

I'm thinking now I'll create a new section in the ini file using the same event id followed by the ID numbers. I want to avoid using the actual names in case

the name changes or simply to avoid the file getting too large.

Also, instead of using -1 in the RegisterSortCallback routine, you should use the listview's control ID/Handle, because now that you've moved things around, the -1 no longer points to the listview.

These are written wrong, you're putting a ListView style in the extended style parameter, which either does nothing or causes the listview to work completely differently than you'd expect depending upon what the value in the extended setting means.

Corrected both.

I still don't get any highlighting of the list item I click on. You can see in the status bar that it does pick it with click or double-click.

It's as though using WM_Notify() stops the normal handling of listsviews. If I disable the function call, highlighting works but then I'll never

be able to double-click to edit.

;Autoit Options
; #NoTrayIcon ;No Tray Icon
Opt("GUIOnEventMode", 1)
Opt("WinTextMatchMode", 1) ;1=complete, 2=quick
Opt("WinTitleMatchMode", 3) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("GUICloseOnESC", 0) ;1=ESC closes, 0=ESC won't close
Opt("GUIResizeMode", 802)
; Opt("GUIResizeMode", 1)


#Include <String.au3>
#include <Date.au3>
#Include <WinAPI.au3>
#include <File.au3>
#include <GuiTab.au3>
;#include <GDIPlus.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiScrollBars.au3>
#include <GuiStatusBar.au3>
#include <GuiToolbar.au3>

; Constants includes
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <ToolbarConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

; Tab groups
Global Const $L_VOLUNTEERS = " Volunteers "
Global Const $L_VOLUNTEER = "Volunteer"
Global Const $L_EVENTS = " Events "
Global Const $L_EVENT = "Event"
Global Const $L_FORMS = " Forms "
Global Const $L_FORM = "Form"
Global Const $L_LABELS = " Labels "
Global Const $L_LABEL = "Label"
Global Const $L_GLOBAL = "Global Options"

; Menus
Global Const $M_FILE = "&File"
Global Const $M_EDIT = "&Edit"
Global Const $M_EVENT = "Even&t"
Global Const $M_VOLUNTEER = "&Volunteer"
Global Const $M_OPTIONS = "&Go To..."

; Buttons
Global Const $L_OK = "&OK"
Global Const $L_DONE = "&Done"
Global Const $L_CANCEL = "&Cancel"
Global Const $L_ADD = "<< &Add"
Global Const $L_REMOVE = "&Remove >>"

; Prompts
Global Const $L_AREYOUSURE = "Are You Sure?"
Global Const $L_CANCELEXIT = "Cancel all changes and exit?"

; Tab items
Global Const $T_Event = 0
Global Const $T_Volunteer = 1
Global Const $T_Forms = 2
Global Const $T_Labels = 3

;Versions Info
Global $ProgName = "Volunteer Coordinator"
Global $VersionBuild = "20130213" ;YEAR|MON|DAY
Global $ProgVersion = "0.1"
GLOBAL $AboutVersion = "2013.02.13 (" & $ProgVersion & ")"

Global $ProgWidth =1024, $ProgHeight = 720

Local $sWidth = 400, $sHeight = 350
Local $hToolbar = 40, $hStatus = 40, $hTabs = $hToolbar+30, $hLists = ($ProgHeight - $hTabs - $hStatus - $hToolbar)

#Region ### START Koda GUI section ### Form=R:\AutoIt Examples\koda_2008-09-03\Forms\VolunteerCoordinator.kxf
Global $MainForm = GUICreate($ProgName, $ProgWidth, $ProgHeight, (@DesktopWidth - $ProgWidth) / 2, (@DesktopHeight - $ProgHeight) / 2, $WS_SIZEBOX + $WS_SYSMENU )
GUISetState(@SW_HIDE)
GUISetBkColor(0xA6CAF0)
GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "")
GUISetOnEvent($GUI_EVENT_RESTORE, "")
Global $TabVol = GUICtrlCreateTab(1, $hTabs-$hToolbar, $ProgWidth-2, $hToolbar, $TCS_TABS)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)

Global $TabSheetEvents = GUICtrlCreateTabItem($L_EVENTS)
Global $ListViewEvents = GUICtrlCreateListView( _
"Date            |Type   |From |To   ", _
2, $hTabs, 815, $hLists-12, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_SORTDESCENDING))
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
EventFullList()
;GUICtrlSetOnEvent(-1, "ListViewEventsClick")
_GUICtrlListView_SetColumnWidth($ListViewEvents, 0, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewEvents, 1, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_RegisterSortCallBack($ListViewEvents, True, True)

Global $ListEventsVol = GUICtrlCreateList("", 819, $hTabs, 202, 618)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "ListEventsVolClick")

Global $TabSheetVolunteers = GUICtrlCreateTabItem($L_VOLUNTEERS)
Global $ListViewVolunteers = GUICtrlCreateListView( _
"Name            |Type       |Home   |Work   |Cell   |Address                |City   |Prov|Postal|Notes                          ", _
2, $hTabs, $ProgWidth-4, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_SORTASCENDING))
GUICtrlSetFont($ListViewVolunteers, 10, 400, 0, "MS Sans Serif")
VolunteerFullList()
;GUICtrlSetOnEvent(-1, "ListViewVolunteersClick")
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 0, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 1, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 2, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 3, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 4, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 6, $LVSCW_AUTOSIZE_USEHEADER )
_GUICtrlListView_SetColumnWidth($ListViewVolunteers, 9, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_RegisterSortCallBack($ListViewVolunteers, False, True)

Global $TabSheetForms = GUICtrlCreateTabItem($L_FORMS)
Global $ListViewForms = GUICtrlCreateListView( _
"Name            |Style          ", _
2, $hTabs, 600, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_SORTASCENDING))
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "ListViewFormsClick")

Global $TabSheetLabels = GUICtrlCreateTabItem($L_LABELS)
GUICtrlSetState(-1,$GUI_SHOW)
Global $ListViewLabels = GUICtrlCreateListView( _
"Name            |Style          ", _
2, $hTabs, 600, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_SORTASCENDING))
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;~ Sleep(1000)
;~ GUICtrlSetState($TabSheetVolunteers, $GUI_SHOW)
;~ Sleep(1000)
;~ GUICtrlSetState($TabSheetForms, $GUI_SHOW)
;~ Sleep(1000)
;~ GUICtrlSetState($TabSheetLabels, $GUI_SHOW)
;~ Sleep(1000)
GUICtrlSetState($TabSheetEvents, $GUI_SHOW)
;GUICtrlSetOnEvent(-1, "TabVolChange")

GUICtrlCreateTabItem("") ;end of tabs
sleep(500)
_GUICtrlTab_SetCurFocus($TabVol, $T_Event)
; _GUICtrlTab_SetCurFocus($ListViewEvents, $T_Event)


;==> FILE menu
Local $MenuFile = GUICtrlCreateMenu($M_FILE)
Local $MenuFileOpen = GUICtrlCreateMenuItem("Open..." & @tab & "Ctrl+O", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileOpenClick")
Local $MenuFileSave = GUICtrlCreateMenuItem("Save" & @tab & "Ctrl+S", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileSaveClick")
Local $MenuFileSaveAs = GUICtrlCreateMenuItem("Save As..." & @tab & "F3", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileSaveAsClick")
Local $MenuFilePrint = GUICtrlCreateMenuItem("Print..." & @tab & "Ctrl+P", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFilePrintClick")
Local $MenuFileExit = GUICtrlCreateMenuItem("Exit" & @tab & "Ctrl+E", $MenuFile)
;GUICtrlSetOnEvent(-1, "MenuFileExitClick")

;==> EDIT menu
Local $MenuEdit = GUICtrlCreateMenu($M_EDIT)
;Local $MenuEditCut = GUICtrlCreateMenuItem("Cut" & @tab & "Ctrl+X", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditCutClick")
;Local $MenuEditCopy = GUICtrlCreateMenuItem("Copy" & @tab & "Ctrl+C", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditCopyClick")
;Local $MenuEditPaste = GUICtrlCreateMenuItem("Paste" & @tab & "Ctrl+V", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditPasteClick")
Local $MenuEditListItem = GUICtrlCreateMenuItem("Edit List Item" & @tab & "F2", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuEditListItemClick")
Local $MenuGlobalOptions = GUICtrlCreateMenuItem($L_GLOBAL & @tab & "F4", $MenuEdit)
;GUICtrlSetOnEvent(-1, "MenuGlobalOptionsClick")

;==> EVENT menu
Local $MenuEvent = GUICtrlCreateMenu($M_EVENT)
Local $MenuEventAdd = GUICtrlCreateMenuItem("Add " & $L_EVENT & @tab & "F9", $MenuEvent)
;GUICtrlSetOnEvent(-1, "MenuEventAddClick")
Local $MenuEventEdit = GUICtrlCreateMenuItem("Edit " & $L_EVENT & @tab & "F10", $MenuEvent)
;GUICtrlSetOnEvent(-1, "MenuEventEditClick")
Local $MenuEventDelete = GUICtrlCreateMenuItem("Delete " & $L_EVENT & @tab & "", $MenuEvent)
;GUICtrlSetOnEvent(-1, "MenuEventDeleteClick")

;==> VOLUNTEER menu
Local $MenuVolunteer = GUICtrlCreateMenu($M_VOLUNTEER)
Local $MenuVolunteerAdd = GUICtrlCreateMenuItem("Add " & $L_VOLUNTEER & @tab & "F11", $MenuVolunteer)
;GUICtrlSetOnEvent(-1, "MenuVolunteerAddClick")
Local $MenuVolunteerEdit = GUICtrlCreateMenuItem("Edit " & $L_VOLUNTEER & @tab & "F12", $MenuVolunteer)
;GUICtrlSetOnEvent(-1, "MenuVolunteerEditClick")
Local $MenuVolunteerDelete = GUICtrlCreateMenuItem("Delete " & $L_VOLUNTEER & @tab & "", $MenuVolunteer)
;GUICtrlSetOnEvent(-1, "MenuVolunteerDeleteClick")

;==> OPTIONS menu
Local $MenuOptions = GUICtrlCreateMenu($M_OPTIONS)
Local $MenuEventDates = GUICtrlCreateMenuItem($L_EVENT & " Dates" & @tab & "F5", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuEventDatesClick")
Local $MenuVolList = GUICtrlCreateMenuItem($L_VOLUNTEER & " List" & @tab & "F6", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuVolListClick")
Local $MenuForms = GUICtrlCreateMenuItem("Forms" & @tab & "F7", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuFormsClick")
Local $MenuLabels = GUICtrlCreateMenuItem("Labels" & @tab & "F8", $MenuOptions)
;GUICtrlSetOnEvent(-1, "MenuLabelsClick")

;==> HELP menu
Local $MenuHelp = GUICtrlCreateMenu("Help")
;GUICtrlSetOnEvent(-1, "MenuHelpClick")
Local $MenuHelpAbout = GUICtrlCreateMenuItem("About" & @tab & "F1", $MenuHelp)
;GUICtrlSetOnEvent(-1, "MenuHelpAboutClick")


; MENU hotkeys
;Local $MainForm_AccelTable[3][2] = [ ["^x", $MenuEditCut],["^c", $MenuEditCopy],["^v", $MenuEditPaste] ]
Local $MainForm_AccelTable[22][2] = [ _
["^!f", $MenuFile],["^o", $MenuFileOpen],["^s", $MenuFileSave],["{F3}", $MenuFileSaveAs],["^p", $MenuFilePrint], ["^e", $MenuFileExit], _
["^!e", $MenuEdit],["{F2}", $MenuEditListItem],["{F4}", $MenuGlobalOptions], _
["^!t", $MenuEvent],["{F9}", $MenuEventAdd],["{F10}", $MenuEventEdit], _
["^!v", $MenuVolunteer],["{F11}", $MenuVolunteerAdd],["{F12}", $MenuVolunteerEdit], _
["^!g", $MenuOptions],["{F5}", $MenuEventDates],["{F6}", $MenuVolList],["{F7}", $MenuForms],["{F8}", $MenuLabels], _
["^!h", $MenuHelp],["{F1}", $MenuHelpAbout] _
]
GUISetAccelerators($MainForm_AccelTable, $MainForm)


Global $ToolBar = _GUICtrlToolbar_Create($MainForm, 0)
_GUICtrlToolbar_AddButton($ToolBar, 0, 0)
_GUICtrlToolbar_AddButton($ToolBar, 0, 1)
_GUICtrlToolbar_AddButton($ToolBar, 0, 2)
_GUICtrlToolbar_AddButton($ToolBar, 0, 3)
_GUICtrlToolbar_AddButton($ToolBar, 0, 4)
_GUICtrlToolbar_AddButton($ToolBar, 0, 5)

Global $StatusBar = _GUICtrlStatusBar_Create($MainForm)
_GUICtrlStatusBar_SetSimple($StatusBar)
_GUICtrlStatusBar_SetText($StatusBar, "Simple status bar window text goes here.")
_GUICtrlStatusBar_SetMinHeight($StatusBar, $hStatus)

GUISetFont(10, 400, 0, "MS Sans Serif", $MainForm)
GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose")
;GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, '_PRIMARYdown')
GUISetOnEvent($GUI_EVENT_RESTORE, "")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "")
GUISetOnEvent($GUI_EVENT_RESIZED, "")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

#EndRegion ### END Koda GUI section ###

GUISwitch($MainForm)
GUISetState(@SW_SHOW)

;GUISetState(@SW_SHOW, $MainForm)
While 1
sleep(100)
; If (GUIGetMsg() = $GUI_EVENT_CLOSE) Then ExitLoop
WEnd

GUISetState(@SW_HIDE)
GUIDelete()
_GUICtrlListView_UnRegisterSortCallBack($ListViewEvents)
_GUICtrlListView_UnRegisterSortCallBack($ListViewVolunteers)
GUIRegisterMsg($WM_NOTIFY, "")
Exit

Func MainFormClose()
Exit
EndFunc ;==>MainFormClose

Func EventFullList()
GUICtrlCreateListViewItem("February 12, 2013|All Day||", $ListViewEvents)
GUICtrlCreateListViewItem("February 13, 2013|AM||", $ListViewEvents)
GUICtrlCreateListViewItem("February 13, 2013|PM||", $ListViewEvents)
GUICtrlCreateListViewItem("February 15, 2013|From|11:00|18:00", $ListViewEvents)
EndFunc ;==>EventFullList

Func VolunteerFullList()
GUICtrlCreateListViewItem("Dan Black|Parent|(514)345-6789|(514)345-9876|(608)345-1234|239 Temple Drive|Montreal|QC|H2N3M4|Coordinator", $ListViewVolunteers)
GUICtrlCreateListViewItem("Mary Pigment|Staff|(519)242-2020|(519)356-0176|(519)675-1201|21st Avenue|London|ON|J7S5M9|Principal", $ListViewVolunteers)
GUICtrlCreateListViewItem("Paul Green|Friend/Family|(514)349-6699|(514)349-5555|(514)698-9857|423 Happle / Apt 12|Montreal|QC|H2N5L1|", $ListViewVolunteers)
GUICtrlCreateListViewItem("Sheila Blue|Other|(514)345-7733|(514)655-4562|(608)345-1234|239 Temple Drive|Montreal|QC|H2N3M4|Coordinator", $ListViewVolunteers)
EndFunc ;==>VolunteerFullList

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo

$hWndListView1 = GUICtrlGetHandle($ListViewEvents)
$hWndListView2 = GUICtrlGetHandle($ListViewVolunteers)

$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")

Switch $hWndFrom
Case $hWndListView1
Switch $iCode
             Case $LVN_COLUMNCLICK ; A column was clicked
                 $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                 ; Kick off the sort callback
                 _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
; No return value
             Case $LVN_ITEMCHANGING ; An item is changing
                 $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                 Return True ; prevent the change
                 ;Return False ; allow the change
Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You clicked on: " & $text)
; _GUICtrlListView_SetItemSelected($ListViewEvents, DllStructGetData($tInfo, "Index"))
Return $GUI_RUNDEFMSG
; No return value
Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You double-clicked on: " & $text)
Return $GUI_RUNDEFMSG
; DO EDIT HERE
; No return value
             Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
$text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You hit ENTER on: " & $text)
EndSwitch

Case $hWndListView2
Switch $iCode
             Case $LVN_COLUMNCLICK ; A column was clicked
                 $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                 ; Kick off the sort callback
                 _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
                 ; No return value
             Case $LVN_ITEMCHANGING ; An item is changing
                 $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                 Return True ; prevent the change
                 ;Return False ; allow the change
Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You clicked on: " & $text)
; _GUICtrlListView_SetItemSelected($ListViewVolunteers, DllStructGetData($tInfo, "Index"))

;Return $GUI_RUNDEFMSG
; No return value
Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You double-clicked on: " & $text)
;Return $GUI_RUNDEFMSG
; No return value
; DO EDIT HERE
             Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
$text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index"))
_GUICtrlStatusBar_SetText($StatusBar, "You hit ENTER on: " & $text)
                 ; No return value
; DO EDIT HERE
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Edited by Garp99HasSpoken
1 person likes this

Share this post


Link to post
Share on other sites

The $LVN_ITEMCHANGING switch case is throwing it off. You're returning true from that, but it's being actioned on every click on the Listview, so you never get the $GUI_RUNDEFMSG returned correctly later.

Case $LVN_ITEMCHANGING ; An item is changing
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
;~  Return True ; prevent the change

Commenting out the Return True should fix it.


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 Gude
How 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

Share this post


Link to post
Share on other sites

Yes it does...Thanks.

Now the highlighting is there and the up/down keys work, and sorting is all good.

Now on to the Edit/Delete of items from the list.

I've looked at CVS Editor and EZ-Track but neither does both a ListView and Edit of the form.

Are there any other examples that I simply haven't found yet?

Share this post


Link to post
Share on other sites

Deleting items is easy, editing them a little harder, but not difficult once you start reading the help file for the _GUICtrlListview_* functions. You can read the text into another GUI to edit the items, then update the listview with the altered information.


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 Gude
How 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

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  
Followers 0