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

    • 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)  
    • 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-08-08)
      _AD_IsPasswordExired: It compares the expiration time (UTC - but should be local time) with the current time (local time). Which is 2 hours off here. Will be fixed in the next version.
      Or replace line If $aTemp[11] <= _NowCalc() Then Return 1 with
      If $aTemp[9] <= _NowCalc() Then Return 1  
      Things to come: (last changed: 2018-08-08)
      Internal function to convert Large Integer to Date String. _AD_ModifyAttribute fully supports single-value and multi-value attributes. Returns better error information. Better support for Fine Grained Password Policy
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort
    • 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!
       
×