Jump to content
Sign in to follow this  
xinx

GUICtrlCreateListView using UP and DOWN buttons

Recommended Posts

xinx

I'm have a working program that displays the users in Active Directory. When a user's name is clicked on it displays their details (profile folder, work folder, etc). However, what I'd really like to do is be able to eliminate using the mouse as much as possible, so instead of having to click on each user's name, you can use the UP and DOWN arrows and it will act as though their name has been clicked on (if that makes any sense?).

Here's some of the code so far:

$ADListView = GUICtrlCreateListView("Login Name|Display Name", 140, 60, 220, 280);A ListView to display the users

; Adjust the ADListView column headers
_GUICtrlListView_SetColumnWidth($ADListView, 0, 100)
_GUICtrlListView_SetColumnWidth($ADListView, 1, 116)

Func UpdateUserList()
_AD_Open()
$SelectedUserType = GUICtrlRead($UserTypeCombo)

;Get the base OU for the user type
$SelectedUserTypeBaseOU = IniRead("iniUsers.ini", $SelectedUserType, "BaseOU", "NotFound")
;Get the filtered results from the AD using base OU
$ADData = _AD_GetObjectsInOU($SelectedUserTypeBaseOU, "(&(objectclass=user)(name=*))", 2, "sAMAccountName,distinguishedName,displayname", "displayname")
GUICtrlSetData($ADListView, $ADData)
_GUICtrlListView_DeleteAllItems($ADListView)
GUICtrlSetData($UserPropertiesEditBox, "Properties of Selected User")
$SelectedUser = ""
;For each AD user, add an item in in the ListView
For $i = 1 To UBound($ADData) - 1
GUICtrlCreateListViewItem($ADData[$i][0] & "|" & $ADData[$i][2], $ADListView)
GUICtrlSetOnEvent(-1, "ListClicked") ; For each item, add the required event
Next
_AD_Close()
EndFunc ;==>UpdateUserList

Func ListClicked()
$ItemString = GUICtrlRead(@GUI_CtrlId)
$ItemArray = StringSplit($ItemString, "|")
$SelectedUser = $ItemArray[1]
_AD_Open()
$givenName = _AD_GetObjectAttribute($SelectedUser, "givenName")
$SN = _AD_GetObjectAttribute($SelectedUser, "SN")
$displayName = _AD_GetObjectAttribute($SelectedUser, "displayName")
$profilePath = _AD_GetObjectAttribute($SelectedUser, "profilePath")
$homeDirectory = _AD_GetObjectAttribute($SelectedUser, "homeDirectory")
$homeDrive = _AD_GetObjectAttribute($SelectedUser, "homeDrive")
$GroupArray = _AD_GetUserGroups($SelectedUser)
GUICtrlSetData($UserPropertiesEditBox, "")
_GUICtrlEdit_AppendText($UserPropertiesEditBox, "Properties of Selected User")
_GUICtrlEdit_AppendText($UserPropertiesEditBox, @CRLF & @CRLF & "First Name: " & $givenName)
_GUICtrlEdit_AppendText($UserPropertiesEditBox, @CRLF & @CRLF & "Last Name: " & $SN)
_GUICtrlEdit_AppendText($UserPropertiesEditBox, @CRLF & @CRLF & "Login Name: " & $SelectedUser)
_GUICtrlEdit_AppendText($UserPropertiesEditBox, @CRLF & @CRLF & "Profile Directory: " & $profilePath)
_GUICtrlEdit_AppendText($UserPropertiesEditBox, @CRLF & @CRLF & "Home Directory: " & $homeDirectory & " (" & $homeDrive & ")")
_GUICtrlEdit_AppendText($UserPropertiesEditBox, @CRLF & @CRLF & "Group Membership:")
For $i = 1 To UBound($GroupArray) - 1
_GUICtrlEdit_AppendText($UserPropertiesEditBox, @CRLF & _AD_FQDNToDisplayname($GroupArray[$i]))
Next

_AD_Close()
EndFunc ;==>ListClicked

Any help would be great, thank you! :)

Edited by xinx

Share this post


Link to post
Share on other sites
xinx

P.s. I suspect it needs to be something in the

;For each AD user, add an item in in the ListView
For $i = 1 To UBound($ADData) - 1
GUICtrlCreateListViewItem($ADData[$i][0] & "|" & $ADData[$i][2], $ADListView)
GUICtrlSetOnEvent(-1, "ListClicked") ; For each item, add the required event
Next

So that when the UP or DOWN arrows are used they GUICtrlSetOnEvent(-1, "ListClicked") - I just can't seem to find out how.

Edited by xinx

Share this post


Link to post
Share on other sites
xinx

Any suggestions welcome - also if I have missed out anything that anyone needs in order to help then please let me know! :idiot:

Share this post


Link to post
Share on other sites
abberration

Hello, xinix. Today, I have been trying to do the same thing you are doing. It doesn't appear to be an easy thing to do. The closest I have come so far has been using _GUICtrlListView_GetSelectionMark to find the zero based index of the selected row. Then, you can use _GUICtrlListView_InsertItem to insert an item. Note that it does not insert multiple columns. Using the separator "|" does not split your data. Lastly, you can use _GUICtrlListView_DeleteItemsSelected to delete any unwanted rows.

I'm not very hopeful of an easy solution. Looking at previous solutions to small problems like editing a second column, I have seen dozens of lines of code with things I don't fully understand yet (like creating structures, calling DLLs and $WM_NOTIFY).

As easy as AutoIt is on most things, I thought there would be a _RowMoveUP and _RowMoveDown kind of function. Maybe there's some technical reason why it can't be done so easily.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites
xinx

Hi abberration

Thank you - I thought I was missing something obvious but at least I know it's not and that others have had similar issues. Sad though :-(

All the best

xinx

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  

  • Similar Content

    • water
      By water
      Extensive library to control and manipulate Microsoft Active Directory.

      Threads: Development - General Help & Support - Example Scripts - Wiki
      Previous downloads: 30467
       
      Known Bugs: (last changed: 2018-10-19)
      None
        Things to come: (last changed: 2018-11-15)
      _AD_GetPasswordInfo will correctly handle DCs which do not provide computed properties (DC functionality < Windows Server 2008 Mode).
      Warning information will no longer be returned using macro @error, macro @extended will now be used (which is much more sensible).
      The codes returned will be changed as well as they returned wrong results. _AD_CreateMailboxPS will allow to run in the background without visible window when PowerShell gets called.
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort
    • tweakster2010
      By tweakster2010
      Hello All,
      It has been a long time since I posted, role changes etc involving work and I finally am back to modifying a program I write in AutoIt that has AD integration. I am at a point where we are modifying our structure where I am validating users access via what Distribution List they belong to in our AD OU's. What I have run into is the OU is a sub OU of a sub OU now. Meaning: CN=team, OU=DL, OU=Groups, DC=business.com(working), is now CN=Team, OU=SubDL, OU=DL, OU=Groups, DC=business.com (Not working).  Just curious if the AD functionality should be able to read it or maybe I am missing something?
       
      ElseIf _AD_IsMemberOf("CN=Team,OU=Distribution Lists,OU=Groups,DC=business,DC=com", $sFQDN_User) Then #works for primary Distro ElseIf _AD_IsMemberOf("CN=Team,OU=SubDL,OU=Distribution Lists,OU=Groups,DC=business,DC=com", $sFQDN_User) Then #fails for subOU of DL How I am accessing AD to get the information:
      _AD_Open() Global $aUser = _AD_GetObjectsInOU("", "(&(objectCategory=person)(objectClass=user)(samaccountname=" & @UserName & "))", 2, "ADsPath,Displayname,distinguishedName") Global $sDisplayName0 = $aUser[1][1] ; Displayname ;MsgBox(0,"", $sDisplayName0) If StringLeft($sDisplayName0, 2) = "9-" Then $Displaynamestring = StringTrimLeft($sDisplayName0, 2) $Displaynamestring1 = StringTrimRight($Displaynamestring, 6) The error code generated is a 1 with a 0 extended. I assume it is because it cannot find the SubOU.
       
      Thanks for any assistance.
    • antmar904
      By antmar904
      I'm trying to read all cells used in column "C" in excel to an array but not sure how.
       
      Local $NameArray = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, $oWorkbook.Range["C"].End)  
    • Blois
      By Blois
      Hey Guys,
      Good?
      I'm ned help to consult in other domain. My three domain contains any domains.
      How do I get this query done?
       
      Tks for the Help!
       
×