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

  • Home
  • SEARCH
  • 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 365401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:32:01+00:00 2026-05-12T13:32:01+00:00

I have an ObservableCollection of about 1000 objects that needs to be filtered (searched)

  • 0

I have an ObservableCollection of about 1000 objects that needs to be filtered (searched) by the end user. The user must be able to search by name or employee id. The List Control consumes FilteredEmployees and Employees is loaded up with everything on page load.

I currently have it set up as such:

public ObservableCollection<EmployeeServicesData> Employees { get; set; }
public ObservableCollection<EmployeeServicesData> FilteredEmployees { get; set; }

internal void FilterEmployee(string searchText, bool isByName)
{
    if (searchText.Length > 0)
    {
        IEnumerabe<EmployeeServicesData> filter;

        if (isByName)
            filter = Employees.Where(x => x.Name.Length >= searchText.Length).Where(x => x.Name.Substring(0, searchText.Length) == searchText.ToUpper());
        else
            filter = Employees.Where(x => x.EmployeeNumber.ToString().Length > searchText.Length).Where(x => x.EmployeeNumber.ToString().Substring(0, searchText.Length) == text);

        foreach (EmployeeServicesData employee in filter)
            FilteredEmployees.Add(employee);
    }
}

Sanitation is handled before this method.

This doesn’t smell very efficent. Should I use two methods for this, or is there a better way to handle filtering?

I’d like to keep Employees at an unchanged state so I can repopulate FilteredEmployees to the full list without hitting the DB again.

  • 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-05-12T13:32:01+00:00Added an answer on May 12, 2026 at 1:32 pm

    It looks like you’re trying to see if searchText is contained in the Employee name, or in the Employee Number.

    You could do this instead:

    x.Name.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0
    x.EmployeeNumber.ToString().IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0
    

    Or you could use StartsWith instead of IndexOf.

    Edit: Another problem with List Controls with large amounts of data in them is that it takes a long time to render. So if you have it unfiltered when you start and Silverlight or WCF or whatever has to render all 1000 into the control even though you don’t see all of them, it can take a little bit of time. Silverlight 3 has UI Virtualization, which would probably be the best optimization you could do here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ObservableCollection of addresses that I am binding to a ListBox. Then
I have an ObservableCollection of Task objects. Each Task has the following properties: AssignedTo
I'm not sure how to go about this exactly. I have a static ObservableCollection
I have a View that displays a DataGrid which is bound to an ObservableCollection
I have a class Seive that implements INotifyPropertyChanged. I have a ObservableCollection SeiveList.I input
I have information that was gathered from a service about TFS builds put into
In my 3d application, I have a TreeView that is databound to an ObservableCollection
I have the following code that should display some information about ContactLists in a
I have an application that needs to display a grid of data consisting mostly
I have a ObservableCollection that's bound to a ListBox in WPF. I want the

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.