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

    • Trinnon
      By Trinnon
      I have a question about the @error logging features in _AD_CreateUser.  Hopefully I am just missing something obvious.
      In my app I am creating a user if it does not exist then manipulating some attributes. 
      If the user does exist I would then call another function to remove groups from the user and modify some attributes.
      My question is...
      If the user already Exists, the _AD_CreateUser option gives $iValue = 0 and @error = 0.
      How can @error = 1 for the condition that the user already exists?
       
      I copied a small ship of the code in question along with my full .au3. 
      I am using AD UDF 1.4.9.0 (Water, thanks for the awesome work on this!!!).
      $iValue = _AD_CreateUser ($sOU, $sUser, $sCN)
      If $iValue = 1 Then
            _FileWriteLog ($Log, "Func UserCheck() - User '" & $sUser & "' successfully created ==> Calling UserAttribsNewUser Function.")
            Call ("NewUser")
      ElseIf @error = 1 Then
            _FileWriteLog ($Log, $sUser & " already exists ==> Calling UserAttribsExistingUser Function.")
            Call ("ExistingUser")
       
      AccountSettingConfigurations-Test1.au3
       
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I have a request
      I want a simplified example of how to create the toolbar
      With an example of pressing the buttons inside this bar
      for example
      Toolbar contains Three buttons
      open, save, And delete
      and i want  If i press a button from among these buttons a MSGBox appears
      I know this is easy
      But I did not know how to do it
      I hope you help me
      I apologize for the inconvenience
      Thank you in advance
    • 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-06-01)
      None  
      Things to come: (last changed: 2018-06-01)
      None
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort
    • rudi
      By rudi
      Hello,
       
      from this posting of @Jos https://www.autoitscript.com/forum/topic/162005-getting-windows-users-account-type/?do=findComment&comment=1176831
      I can smoothly check, if a user is a *DIRECT* group member. Has anybody some code to check also, if a user is a *INDIRECT* member of a cascaded group construct?  Maybe with @Melba23 's AD UDF?
       
      The required rights are granted to group "Dept_B" User John is member of group "Dept_A" Group "Dept_A" is member of the group "Dept_B" So in the AD / NTFS FS environment John finally has the rights of both groups But when checking his "membership to group Dept_B" the result is "no member". The approach I can think of would be, to check all Group Members of group "Dept_B" whether they are of type group, then check again if "John" is member of than " 2nd level group"
      Func UserInGroup($InGroup,$ThisUser=@LogonDomain & "/" & @UserName) Local $objUser = ObjGet("WinNT://" & $ThisUser ) For $oGroup in $objUser.Groups If $oGroup.Name = $InGroup Then Return 1 EndIf Next Return 0 EndFunc Any suggestions appreciated, regards, Rudi.
    • water
      By water
      ADAT is a tool to simplify common AD administration tasks. Every administration task has its own tab. It is easy to add new functions (tabs) to the tool. Some often used functions are already available: list users, computers, OUs. File ADAT.ini can be customized to hold the AD logon information if necessary.
      Known Bugs:
      2018-03-07: If the Script started from SciTE works but the "Process" button in the compiled exe does not do anything then please add the following line at the top of your script:
      #Au3Stripper_Ignore_Funcs=Process_Tab*
        BTW: If you like this tool please click the "I like this" button. This tells me where to next put my development effort
×