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 7732459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:44:06+00:00 2026-06-01T06:44:06+00:00

I am trying to filter an listbox with text from a textbox, realTime. Here

  • 0

I am trying to filter an listbox with text from a textbox, realTime.

Here is the code:

private void SrchBox_TextChanged_1(object sender, EventArgs e)
{
  var registrationsList = registrationListBox.Items.Cast<String>().ToList();
  registrationListBox.BeginUpdate();
  registrationListBox.Items.Clear();
  foreach (string str in registrationsList)
  {
    if (str.Contains(SrchBox.Text))
    {
      registrationListBox.Items.Add(str);
    }
  }
  registrationListBox.EndUpdate();
}

Here are the issues:

  1. When I run the program i get this error: Object reference not set to an instance of an object

  2. If I hit backspace, my initial list is not shown anymore. This is because my actual list of items is now reduced, but how can I achieve this?

Can you point me in the right direction?

  • 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-01T06:44:08+00:00Added an answer on June 1, 2026 at 6:44 am

    It’s hard to deduct just from the code, but I presume your filtering problem born from the different aspects:

    a) You need a Model of the data shown on ListBox. You need a colleciton of “Items” which you hold somewhere (Dictionary, DataBase, XML, BinaryFile, Collection), some kind of Store in short.

    To show the data on UI you always pick the data from that Store, filter it and put it on UI.

    b) After the first point your filtering code can look like this (a pseudocode)

    var registrationsList = DataStore.ToList(); //return original data from Store
    
    registrationListBox.BeginUpdate();
    registrationListBox.Items.Clear();
    
    if(!string.IsNullOrEmpty(SrchBox.Text)) 
    {
      foreach (string str in registrationsList)
      {                
         if (str.Contains(SrchBox.Text))
         {
             registrationListBox.Items.Add(str);
         }
      }
    }
    else 
       registrationListBox.Items.AddRange(registrationsList); //there is no any filter string, so add all data we have in Store
    
    registrationListBox.EndUpdate();
    

    Hope this helps.

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

Sidebar

Related Questions

I'm trying to filter out some garbage text from a string with regex but
I am trying to filter a list, here is the code: test=['aaa','bbb','ccc','ddd','footer','header'] def rm_hf(x):
I'm trying to filter a listview, using a textbox control via an object datasource.
I'm trying to filter a table from an alphabetical <select> input with jQuery. I
I am trying to filter for an object that has a Title field, and
I am trying to display filenames in a listbox, retrieved from a particular directory.
I am trying to save the items from a listbox to a file. So
Hi i was trying to filter a large of text file using Regex.Split with
I am trying to filter stop-words from the following documents using package tm .
I'm trying to filter a set of records based on a sub-object's criteria. This

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.