Misuranai Posted February 28, 2022 Share Posted February 28, 2022 Hi, I'm not sure if I am just unable to use the search function but I have a small question concerning listview with checkboxes. I want to read the value from the checked item in the listview (for e.g. in a variable and then show the value in a msgbox). I have an example GUI: #include <WindowsConstants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> $Test = GUICreate("Test",554,274,-1,-1,-1,-1) $list = GUICtrlCreateListView("Test", 0,0,542,266,$LVS_SHOWSELALWAYS, BitOr($LVS_EX_FULLROWSELECT,$LVS_EX_CHECKBOXES,$WS_EX_CLIENTEDGE)) $item = GUICtrlCreateListViewItem("Test Item", $list) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Wend When I check the item ($item) the value "Test Item" should be saved in a variable like $value1. Do you have any ideas how to resolve it? Thanks in Advanced. Best regards Link to comment Share on other sites More sharing options...
Nine Posted February 28, 2022 Share Posted February 28, 2022 There is a few ways to perform such a thing. Here one of them : #include <WindowsConstants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> Global $Test = GUICreate("Test", 554, 274, -1, -1, -1, -1) Global $list = GUICtrlCreateListView("Test", 0, 0, 542, 266, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $WS_EX_CLIENTEDGE)) Global $item1 = GUICtrlCreateListViewItem("Test Item 1", $list) Global $item2 = GUICtrlCreateListViewItem("Test Item 2", $list) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tStruct = DllStructCreate($tagNMHDR, $lParam) If GUICtrlGetHandle($list) = $tStruct.hwndFrom And $tStruct.Code = $LVN_ITEMCHANGED Then $tStruct = DllStructCreate($tagNMLISTVIEW, $lParam) ConsoleWrite("Item selected : " & _GUICtrlListView_GetItemText($list, $tStruct.item) & @CRLF) ConsoleWrite("Is checked : " & _GUICtrlListView_GetItemChecked($list, $tStruct.item) & @CRLF) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY pixelsearch 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Misuranai Posted March 1, 2022 Author Share Posted March 1, 2022 16 hours ago, Nine said: There is a few ways to perform such a thing. Here one of them : #include <WindowsConstants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> Global $Test = GUICreate("Test", 554, 274, -1, -1, -1, -1) Global $list = GUICtrlCreateListView("Test", 0, 0, 542, 266, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $WS_EX_CLIENTEDGE)) Global $item1 = GUICtrlCreateListViewItem("Test Item 1", $list) Global $item2 = GUICtrlCreateListViewItem("Test Item 2", $list) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tStruct = DllStructCreate($tagNMHDR, $lParam) If GUICtrlGetHandle($list) = $tStruct.hwndFrom And $tStruct.Code = $LVN_ITEMCHANGED Then $tStruct = DllStructCreate($tagNMLISTVIEW, $lParam) ConsoleWrite("Item selected : " & _GUICtrlListView_GetItemText($list, $tStruct.item) & @CRLF) ConsoleWrite("Is checked : " & _GUICtrlListView_GetItemChecked($list, $tStruct.item) & @CRLF) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Thanks for the example. Really appreciated. I have a script which is working directly with the Active Directory and I am listing the groups in a listview with checkboxes in an array. Isn't there any options to do like that: For $i = 0 To UBound($groups) -1 If _GUICtrlListView_GetItemChecked($list, $i) = True Then ConsoleWrite(_GUICtrlListView_GetItemText($list, $i)) Else ConsoleWrite("False") EndIf That's just an imagination from my side. It doesn't work for me so but It would be nice to realize this code. Best regards Link to comment Share on other sites More sharing options...
Nine Posted March 1, 2022 Share Posted March 1, 2022 Oookkk, target is moving...Hold on : For $i = 0 To _GUICtrlListView_GetItemCount($list) - 1 If _GUICtrlListView_GetItemChecked($list, $i) Then ConsoleWrite(_GUICtrlListView_GetItemText($list, $i) & @CRLF) Else ConsoleWrite("False" & @CRLF) EndIf Next Netol 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Misuranai Posted March 1, 2022 Author Share Posted March 1, 2022 1 hour ago, Nine said: Oookkk, target is moving...Hold on : For $i = 0 To _GUICtrlListView_GetItemCount($list) - 1 If _GUICtrlListView_GetItemChecked($list, $i) Then ConsoleWrite(_GUICtrlListView_GetItemText($list, $i) & @CRLF) Else ConsoleWrite("False" & @CRLF) EndIf Next Thank you so much! That is what I was looking for. I have just one more question. I will generate a list of the groups into the listview which are unchecked at first. I want to update the "ConsoleWrite" everytime when I check an item from the listview. For example: I check Item1 and then he should give me the ItemText in the output. Afterwards I check another Item for e.g. Item2. Then he should give me Item1 and Item2 in the ouput. How can I realize the code? My goal is to put the groups which is saved in "GetItemText" into an array so that I can add users to the outputted groups in a For loop by using a method. Link to comment Share on other sites More sharing options...
Solution Nine Posted March 1, 2022 Solution Share Posted March 1, 2022 You just need to combine my 2 scripts...Try to put something up, and if you need help just post code using tag as described in the link Misuranai 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Misuranai Posted March 4, 2022 Author Share Posted March 4, 2022 It worked fine. Thanks for the support! 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