nullschritt Posted July 20, 2013 Share Posted July 20, 2013 (edited) Hello all I've reached a small problem in my coding, currently I have a listview which has checkboxes, only one checkbox may be selected at a time, and it's (supposed) to save the selected one in the database and load it as the selected item on restart of the app. However my only problem is I cannot get the text of the row which is currently checked, I would guess that I would have to enumerate every row in listview or somethign of the sort until I found one that was checked, and then get the text of that row? I was wondering if there was maybe a simpler way to do this or already made function to get the at least the row index of the checked row so I can then get it's text? Edited July 21, 2013 by nullschritt Link to comment Share on other sites More sharing options...
FireFox Posted July 20, 2013 Share Posted July 20, 2013 Hi,What's exactly the problem with the examples we gave you in your previous topic?Br, FireFox. Link to comment Share on other sites More sharing options...
nullschritt Posted July 20, 2013 Author Share Posted July 20, 2013 Hi, What's exactly the problem with the examples we gave you in your previous topic? Br, FireFox. Look at what I am trying to do, I need to store the state in a database for persistance. However Im having trouble detecting which row is checked. Link to comment Share on other sites More sharing options...
FireFox Posted July 20, 2013 Share Posted July 20, 2013 I added a simple button and a case in the main while, and it does the trick. I don't know what you tried to do, or you used something else than what I gave you, whatever expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> Global Const $LVM_CHECKED = 8192, $LVM_UNCHECKED = 4096 Global $iLastItemChecked = -1 #region GUI Local $hGUI = GUICreate("MyGUI", 500, 500) Global $iLw1 = GUICtrlCreateListView("Column1|Column2", 10, 10, 480, 250, Default, $LVS_EX_CHECKBOXES) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") For $i = 0 To 9 GUICtrlCreateListViewItem("Item " & $i, $iLw1) Next Local $iBtn1 = GUICtrlCreateButton("Button1", 9, 270, 80, 22) GUISetState(@SW_SHOW, $hGUI) #endregion GUI Local $aText = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iBtn1 If $iLastItemChecked <> -1 Then $aText = _GUICtrlListView_GetItemTextArray($iLw1, $iLastItemChecked) ConsoleWrite($aText[1] & @CrLf) EndIf EndSwitch Sleep(10) WEnd GUIDelete($hGUI) Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $iIDFrom = 0, $iCode = 0, $tNMHDR = 0, $tInfo = 0 $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $iLw1 Switch $iCode Case $LVN_ITEMCHANGING $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) $iNewState = DllStructGetData($tInfo, "NewState") Switch $iNewState Case $LVM_CHECKED If $iLastItemChecked <> -1 Then _GUICtrlListView_SetItemChecked($iLw1, $iLastItemChecked, False) EndIf $iLastItemChecked = DllStructGetData($tInfo, "Item") Case $LVM_UNCHECKED $iLastItemChecked = -1 EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Link to comment Share on other sites More sharing options...
nullschritt Posted July 21, 2013 Author Share Posted July 21, 2013 (edited) I added a simple button and a case in the main while, and it does the trick.I don't know what you tried to do, or you used something else than what I gave you, whatever expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> Global Const $LVM_CHECKED = 8192, $LVM_UNCHECKED = 4096 Global $iLastItemChecked = -1 #region GUI Local $hGUI = GUICreate("MyGUI", 500, 500) Global $iLw1 = GUICtrlCreateListView("Column1|Column2", 10, 10, 480, 250, Default, $LVS_EX_CHECKBOXES) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") For $i = 0 To 9 GUICtrlCreateListViewItem("Item " & $i, $iLw1) Next Local $iBtn1 = GUICtrlCreateButton("Button1", 9, 270, 80, 22) GUISetState(@SW_SHOW, $hGUI) #endregion GUI Local $aText = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iBtn1 If $iLastItemChecked <> -1 Then $aText = _GUICtrlListView_GetItemTextArray($iLw1, $iLastItemChecked) ConsoleWrite($aText[1] & @CrLf) EndIf EndSwitch Sleep(10) WEnd GUIDelete($hGUI) Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $iIDFrom = 0, $iCode = 0, $tNMHDR = 0, $tInfo = 0 $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $iLw1 Switch $iCode Case $LVN_ITEMCHANGING $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) $iNewState = DllStructGetData($tInfo, "NewState") Switch $iNewState Case $LVM_CHECKED If $iLastItemChecked <> -1 Then _GUICtrlListView_SetItemChecked($iLw1, $iLastItemChecked, False) EndIf $iLastItemChecked = DllStructGetData($tInfo, "Item") Case $LVM_UNCHECKED $iLastItemChecked = -1 EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFYNo, I used the exact code you gave me, the above is an exerp from it after it had been integrated among other wm_notify events for other controls.... Also your code doesn't work, it shows the LAST item checked, not the item currently checked.Switch $iNewState Case $LVM_CHECKED If $iLastItemChecked <> -1 Then _GUICtrlListView_SetItemChecked($keyslist, $iLastItemChecked, False) $rows = _GUICtrlListView_GetItemCount($keyslist) _SQLite_Exec(-1, "UPDATE KEYS set prim='0' WHERE prim='1';") MsgBox(64, "", $rows) $text = _GUICtrlListView_GetItemtextarray($keyslist, $iLastItemChecked) _SQlite_Query (-1, "UPDATE KEYS set prim='1' WHERE MD5 = '"&$text[2]&"'", $hQuery) MsgBox(0, $text[1], $text[2]) EndIf $iLastItemChecked = DllStructGetData($tInfo, "Item") Case $LVM_UNCHECKED $iLastItemChecked = -1 EndSwitchShould I perhaps be getting the checked item from a different event (on click instead of on change?) Edited July 21, 2013 by nullschritt Link to comment Share on other sites More sharing options...
FireFox Posted July 21, 2013 Share Posted July 21, 2013 (edited) Also your code doesn't work, it shows the LAST item checked, not the item currently checked. I'm sorry but as there is only one item checked, the last item checked is the item currently checked. OR I am missing something there? Edit: The variable name is $iLastItemChecked, but it can be $iCurrentItemChecked until there is another one checked. Edit2: To be more clear, it depends where you are using the variable. -If you are using it in the WM_NOTIFY func before this line : $iLastItemChecked = DllStructGetData($tInfo, "Item") then it's the LAST item checked, which will be unchecked. -If you are using it at/after this line, it's the CURRENT item checked. So the var name should be $iCurrentItemChecked, maybe that's why it confused you. Br, FireFox. Edited July 21, 2013 by FireFox Link to comment Share on other sites More sharing options...
nullschritt Posted July 21, 2013 Author Share Posted July 21, 2013 (edited) I'm sorry but as there is only one item checked, the last item checked is the item currently checked. OR I am missing something there? Edit: The variable name is $iLastItemChecked, but it can be $iCurrentItemChecked until there is another one checked.Please look at the video below, it shows the code I currently posted in action, perhaps it will help you understand the error I am experiencing, you will note the message box is displaying http://www.youtube.com/watch?v=IPwx3hLdArA Edited July 21, 2013 by nullschritt Link to comment Share on other sites More sharing options...
FireFox Posted July 21, 2013 Share Posted July 21, 2013 As I said in my "Edit2" : Switch $iNewState Case $LVM_CHECKED If $iLastItemChecked <> -1 Then ;LAST item checked _GUICtrlListView_SetItemChecked($iLw1, $iLastItemChecked, False) ;the code you placed here will be executed for the LAST item checked EndIf $iLastItemChecked = DllStructGetData($tInfo, "Item") ;CURRENT item checked ;place your code HERE Case $LVM_UNCHECKED $iLastItemChecked = -1 EndSwitch Link to comment Share on other sites More sharing options...
nullschritt Posted July 21, 2013 Author Share Posted July 21, 2013 I'm sorry but as there is only one item checked, the last item checked is the item currently checked. OR I am missing something there? Edit: The variable name is $iLastItemChecked, but it can be $iCurrentItemChecked until there is another one checked. Edit2: To be more clear, it depends where you are using the variable. -If you are using it in the WM_NOTIFY func before this line : $iLastItemChecked = DllStructGetData($tInfo, "Item") then it's the LAST item checked, which will be unchecked. -If you are using it at/after this line, it's the CURRENT item checked. So the var name should be $iCurrentItemChecked, maybe that's why it confused you. Br, FireFox. Thanks, I moved my code after this line, and it works perfectly now. Link to comment Share on other sites More sharing options...
nullschritt Posted July 21, 2013 Author Share Posted July 21, 2013 Another question though, for anyone who may know the answer, how would I go abotu getting the row checked on the startup of the program? I tried once using a loop and checking each row to see if it was checked or not, but it didn't seem to work properly. Link to comment Share on other sites More sharing options...
FireFox Posted July 21, 2013 Share Posted July 21, 2013 If it's your script, if you check the items according to a database, then save the last item you checked to a variable. Link to comment Share on other sites More sharing options...
nullschritt Posted July 21, 2013 Author Share Posted July 21, 2013 If it's your script, if you check the items according to a database, then save the last item you checked to a variable.Just thought of that, thanks though! 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