Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8820997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:44:46+00:00 2026-06-14T05:44:46+00:00

I have a combobox bound to a datatable that I fill with user’s names

  • 0

I have a combobox bound to a datatable that I fill with user’s names from active directory. This code takes about a minute to complete. Is there a better way that I am missing?

Function users() As DataTable
    Dim dt As DataTable
    Dim dr As DataRow
    Dim idCoulumn As DataColumn
    Dim nameCoulumn As DataColumn

    Dim dirEntry As New System.DirectoryServices.DirectoryEntry("LDAP://CN=Users,DC=myDomain,DC=local")

    Dim oSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
    Dim oResults As SearchResultCollection

    oSearcher.PropertiesToLoad.Add("samAccountName")
    oSearcher.PropertiesToLoad.Add("givenname")
    oSearcher.PropertiesToLoad.Add("sn")
    oSearcher.PropertiesToLoad.Add("cn")
    oSearcher.Filter = "objectCategory=person"
    oResults = oSearcher.FindAll

    dt = New DataTable()
    idCoulumn = New DataColumn("ID", Type.GetType("System.String"))
    nameCoulumn = New DataColumn("Name", Type.GetType("System.String"))

    dt.Columns.Add(idCoulumn)
    dt.Columns.Add(nameCoulumn)

    For Each oResult In oResults
        With oResult.GetDirectoryEntry()
            If .Properties("cn").Value <> "" AndAlso .Properties("samAccountName").Value <> "" AndAlso .Properties("sn").Value <> "" Then
                dr = dt.NewRow()
                dr("ID") = .Properties("samAccountName").Value
                dr("Name") = String.Format("{0},{1} : {2}", .Properties("sn").Value, .Properties("givenname").Value, .Properties("samAccountName").Value)
                dt.Rows.Add(dr)
            End If
        End With
    Next

    dt.DefaultView.Sort = "Name"

    Return dt

End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:44:47+00:00Added an answer on June 14, 2026 at 5:44 am

    @Spevy helped me get to this solution with his proposed answer.

    I changed my Directory entry to:

    Dim dirEntry As New System.DirectoryServices.DirectoryEntry("LDAP://myDomain")
    

    I set my search filter:

    oSearcher.Filter = "(&(objectCategory=user)(objectClass=user))"
    

    And changed my if statement to:

    If .Properties("samAccountName").Value <> "" AndAlso .Properties("sn").Value <> "" Then
    

    I am not sure what adding these lines of code really do but I get the same results whether they are there or not, so I removed them:

    oSearcher.PropertiesToLoad.Add("samAccountName")
    oSearcher.PropertiesToLoad.Add("givenname")
    oSearcher.PropertiesToLoad.Add("sn")
    oSearcher.PropertiesToLoad.Add("cn")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a combobox that is bound to an enum using the following code:
I have a combobox that is bound to a dictionary like this: Dictionary<int, string>
I have a comboBox that is bound to a list of strings from my
i have a combobox which is bound to a datatable column like this: ComboBox.DataContext
I have a ComboBox bound to a collection of objects defined as this. public
I have a ComboBox that has the SelectedItem bound to the ViewModel. <ComboBox SelectedItem={Binding
I have a ComboBox that is bound to an ObservableCollection of custom UserControls. Each
I have a ComboBox that is bound to a DataSource. I want to dynamically
I have a combobox that is bound to ObservableCollection<Item> in the ViewModel. When a
I have a ComboBox with the ItemsSource data bound. This ComboBox also listens to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.