jazzyjeff Posted May 21, 2013 Share Posted May 21, 2013 I am using a function in my script below, and I want to save the items I checked into an Array. I have been able to achieve this, but lets say I now want to go back into that Window and add 2 more items to the array. I am not seeing the options checked that I previously selected. I ran a For loop to compare the items I originally checked in the array and compared it to a list of security groups pulled down from AD, and if they match I run the function _GUICtrlListView_SetItemChecked. However, that doesn't seem to be checked the items for me. Can someone look at this function and see what I am doing wrong please? expandcollapse popupFunc _AllowGroups() _AD_Open() Local $adGroups = _AD_GetObjectsInOU("OU=Security,OU=Groups,DC=domain,DC=com", "(objectclass=group)") _AD_Close() $formAllow = GUICreate("Allowed Security Groups", 280, 320) $listAllow = GUICtrlCreateListView(" ", 15, 15, 250, 250, -1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT)) _GUICtrlListView_SetColumnWidth($listAllow, 0, 232) $btnOK = GUICtrlCreateButton("OK", 115, 280, 70, 25) $btnCancel = GUICtrlCreateButton("Cancel", 195, 280, 70, 25) ;_GUICtrlListView_BeginUpdate($listAllow) If IsArray($chkAllow) Then _ArrayDisplay($chkAllow) _ArrayDisplay($adGroups) For $a = 1 To $adGroups[0] _GUICtrlListView_AddItem($listAllow, $adGroups[$a]) For $i = 1 To $chkAllow[0][0] If $chkAllow[$i][1] = $adGroups[$a] Then MsgBox(0, "", "Item to check: " & $chkAllow[$i][1] & @CR & "Row index check: " & $a) _GUICtrlListView_SetItemChecked($listAllow, $a, True) ExitLoop EndIf Next Next MsgBox(0, '', "Loop Finished.") Else For $a = 1 To $adGroups[0] _GUICtrlListView_AddItem($listAllow, $adGroups[$a]) Next EndIf ;_GUICtrlListView_EndUpdate($listAllow) _setbut1() GUISetState(@SW_SHOW, $formAllow) ;GUISwitch($formAllow) While 6 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE WinActivate("Add Application", "") GUIDelete($formAllow) ExitLoop Case $btnCancel WinActivate("Add Application", "") GUIDelete($formAllow) ExitLoop Case $btnOK If _checkbox_active1($listAllow) = 1 Then $chkAllow = _GuiCtrlListView_GetChecked($listAllow) _ArrayDisplay($chkAllow) EndIf WinActivate("Add Application", "") GUIDelete($formAllow) ExitLoop Case Else _setbut1() EndSwitch WEnd EndFunc ;==>_AllowGroups Thanks for your time. Link to comment Share on other sites More sharing options...
jazzyjeff Posted May 22, 2013 Author Share Posted May 22, 2013 (edited) Thanks to those that looked at this. I found the problem with my code, so I will post below what I used to resolve this. expandcollapse popupFunc _AllowGroups() _AD_Open() Local $adGroups = _AD_GetObjectsInOU("OU=Security,OU=Groups,DC=DOMAIN,DC=COM", "(objectclass=group)") _AD_Close() $formAllow = GUICreate("Allowed Security Groups", 280, 320) $listAllow = GUICtrlCreateListView(" ", 15, 15, 250, 250, -1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT)) _GUICtrlListView_SetColumnWidth($listAllow, 0, 232) $btnOK = GUICtrlCreateButton("OK", 115, 280, 70, 25) $btnCancel = GUICtrlCreateButton("Cancel", 195, 280, 70, 25) For $a = 1 To $adGroups[0] _GUICtrlListView_AddItem($listAllow, $adGroups[$a]) Next If IsArray($chkAllow) Then For $i = 1 To $chkAllow[0][0] _GUICtrlListView_SetItemChecked($listAllow, $chkAllow[$i][0], True) Next EndIf _setbut1() GUISetState(@SW_SHOW, $formAllow) ;GUISwitch($formAllow) While 6 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE WinActivate("Add Application", "") GUIDelete($formAllow) ExitLoop Case $btnCancel WinActivate("Add Application", "") GUIDelete($formAllow) ExitLoop Case $btnOK If _checkbox_active1($listAllow) = 1 Then $chkAllow = _GuiCtrlListView_GetChecked($listAllow) EndIf WinActivate("Add Application", "") GUIDelete($formAllow) ExitLoop Case Else _setbut1() EndSwitch WEnd EndFunc ;==>_AllowGroups Edited May 22, 2013 by jazzyjeff 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