Link to home
Start Free TrialLog in
Avatar of derek7467
derek7467

asked on

vb.net add ldap query results to listview

I have an ldap query i run via a vb.net gui.  What i am trying to do is return each result to its respective listview column.  Via the below code, the first thing i do is create the two columns.  When i try and run the query nothing appends to its respective column.  If i remove the columing the query works fine, can someone help?

   
Dim item As ListViewItem = ListView1.Items.Add("Username")
        Dim item1 As ListViewItem = ListView1.Items.Add("Title")
        For Each i As String In ListBox1.Items
            Dim de As New DirectoryEntry("LDAP://test.com/DC=test,DC=com")
            Dim LdapFilter As String = "(sAMAccountName=" & i & ")"
            Dim searcher As New DirectorySearcher(de, LdapFilter)
            Dim result As SearchResult = searcher.FindOne()
            item.SubItems.Add(result.Properties("sAMAccountName")(0).ToString())
            item1.SubItems.Add(result.Properties("title")(0).ToString())
            Dim ADEntry As DirectoryEntry = New DirectoryEntry(result.Path)
            If result.Properties("displayName") Is Nothing Then
                On Error Resume Next
            End If
        Next

Open in new window

Avatar of derek7467
derek7467

ASKER

Ok, i've gotten this far.  I have a listview that i want to add the ID, samaccountname, and title.  I added the 3 columns to the listview.  I have the below code, but when i run it, it just shows in one long line, and doesnt create the columns.  How can i force it to create the columns and then place each result under each column?

 Dim userIds As IEnumerable(Of String) = {"test1", "test2", "test3"}
        For Each i As String In userids
            Dim de As New DirectoryEntry("LDAP://test.com/DC=test,DC=com")
            Dim LdapFilter As String = "(sAMAccountName=" & i & ")"
            Dim searcher As New DirectorySearcher(de, LdapFilter)
            Dim result As SearchResult = searcher.FindOne()
            ListView1.Items.Add(i)
            ListView1.Items.Add(result.Properties("sAMAccountName")(0).ToString())
            ListView1.Items.Add(result.Properties("title")(0).ToString())
        Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of derek7467
derek7467

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
incase anyone ever needs this!