mark2004 Posted January 9, 2008 Posted January 9, 2008 I would like to have several controls updated as the selection in a listview is changed. I am using the WM_NOTIFY_EVENTS method with the $LVN_ITEMCHANGED event. The problem is that this event apparently fires 3 times when the selection is changed. Here is the portion of my code from within the WM_NOTIFY_EVENTS section: CODE .. .. .. Case $CaseWHSiteListView $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Switch $event Case $LVN_ITEMCHANGED Guictrlsetdata($CaseWHSVDate,_GUICtrlListViewGetItemText($CaseWHSiteListView,-1,1)) If _GUICtrlListViewGetItemText($CaseWHSiteListView,-1,0)="New" Then Guictrlsetdata($CaseWHSVNum,_GUICtrlListViewGetItemCount($CaseWHSiteListView)) Else Guictrlsetdata($CaseWHSVNum,_GUICtrlListViewGetItemText($CaseWHSiteListView,-1,0)) EndIf Guictrlsetdata($CaseWHSVZone,_GUICtrlListViewGetItemText($CaseWHSiteListView,-1,2)) Guictrlsetdata($CaseWHSVDesc,_GUICtrlListViewGetItemText($CaseWHSiteListView,-1,4)) EndSwitch .. .. .. The problem is that the _GUICtrlListViewGetItemText() function is returning an empty string for the 2nd firing of the event and this wipes out my the selections in my combobox due to how the Guictrlsetdata() function works. Any ideas on how to do this. It seems like a simple enough concept........ Thanks
Siao Posted January 9, 2008 Posted January 9, 2008 Get NewState value from NMLISTVIEW structure, BitAND it with $LVIS_SELECTED and if the result is true, it will be the newly selected item. Then get iItem value to get index of the item. Other notifications are for the item that was deselected. See _GUICtrlListView_Create() example in UDFs helpfile to see how to work with NMLISTVIEW struct from LVN_ITEMCHANGED. "be smart, drink your wine"
mark2004 Posted January 9, 2008 Author Posted January 9, 2008 Thanks, That sounds like what I need. I unfortunately am not running the latest version of AutoIt so I don't have the _GuiCtrlListView_Create() function you referenced. I don't want to upgrade the installation in the middle of this project either. I couldn't find this function's information listed on the website. Could someone either post it here or tell me where I can access the info for this function. Thanks!
Siao Posted January 9, 2008 Posted January 9, 2008 (edited) ;Const $LVIS_SELECTED = 0x2 ;. Switch $event Case $LVN_ITEMCHANGED $tNMLISTVIEW = DllStructCreate("hwnd;uint;uint;int iItem;int;uint iNewState;uint;uint;long;long;lparam", $lParam) If BitAND(DllStructGetData($tNMLISTVIEW, "iNewState"), $LVIS_SELECTED) Then $iItem = DllStructGetData($tNMLISTVIEW, "iItem");index of selected item EndIf EndSwitch ;. Edited January 9, 2008 by Siao "be smart, drink your wine"
mark2004 Posted January 10, 2008 Author Posted January 10, 2008 Thanks!! ;Const $LVIS_SELECTED = 0x2 ;. Switch $event Case $LVN_ITEMCHANGED $tNMLISTVIEW = DllStructCreate("hwnd;uint;uint;int iItem;int;uint iNewState;uint;uint;long;long;lparam", $lParam) If BitAND(DllStructGetData($tNMLISTVIEW, "iNewState"), $LVIS_SELECTED) Then $iItem = DllStructGetData($tNMLISTVIEW, "iItem");index of selected item EndIf EndSwitch ;.
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