VB.NET WinForm Fill List View with AD Users

I have already got my List View to populate with users from AD, the problem is that I am trying to limit what shows in that list view.  
Example:  A person choosed A-F and then clicks show and it shows all users with a username that starts with A-F.
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click

        Dim dirEntry As DirectoryEntry = New DirectoryEntry("LDAP://10.10.10.235/CN=Users,DC=domain,DC=com")
        dirEntry.Username = "domain\administrator"
        dirEntry.Password = "password"
        If lbxSelectUser.Items.Count > 1 Then
            MsgBox("Patience Is Not 1 of your virtues")
        Else
            Dim mySearcher As New DirectorySearcher(dirEntry)
            mySearcher.Filter = "(&(objectClass=User)(objectCategory=person))"
            For Each resEnt As SearchResult In mySearcher.FindAll()
                lbxSelectUser.Items.Add(resEnt.Properties("sAMAccountName")(0).ToString())
            Next
            lbxSelectUser.Sorted = True
        End If
    End Sub

Open in new window

james_martinAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
You can make up the SearchFilter string like below

sn=a* (all names starting with a)
(sn=a*)(sn=b*) (all names starting with a or b)

Check here
http://msdn.microsoft.com/en-us/library/aa746475%28VS.85%29.aspx
0
 
Thunder724Commented:
James, in this situation what I would think of doing is placing all the AD info into a DATASET first; and use DATAVIEWS to populate your ListView. That way you can use simple SQL like syntac for the DATAVIEW FILTER.
0
 
james_martinAuthor Commented:
The problem with this is that it will take a lot of time to list this out, over 10,000 users.  The purpose of breaking it out is to cut down on time to pull information.
0
 
Thunder724Commented:
   
CodeCruiser's suggestion sounds like a good idea if you are only going to query a small subset once or twice at a time.  If you are going to do multiple searches then the initial time to build the dataset is, in my opinion, more economical.  
0
All Courses

From novice to tech pro — start learning today.