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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:57:53+00:00 2026-06-18T11:57:53+00:00

I make a listbox and it works perfectly, I also made a search function,

  • 0

I make a listbox and it works perfectly, I also made a search function, but I want to hide the items in the listbox and show them only when searched through index.
here is my code for adding items

private void Savebtn_Click(object sender, EventArgs e)
{
    addTolist(gatherItem());
    refreshView();
}

private void addTolist(Person p)
{
    Person.listperson.Add(p);
}

private void refreshView()
{
    listBox1.Items.Add(getItem());
}

private String getItem()
{
    String result = null;
    foreach (Person p in Person.listperson)
    {
        result = p.lastname;
    }
    return result;
}

and this is my code for search

private void button1_Click(object sender, EventArgs e)
{
    int index = listBox1.FindString(textBox6.Text);
    if (0 <= index)
    {
        listBox1.SelectedIndex = index;
    }
}

Is there a way for this? thanks 🙂

  • 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-18T11:57:54+00:00Added an answer on June 18, 2026 at 11:57 am

    There is no easy way to do this with winforms. It a lot easier with WPF. With winforms you will have to remove the items. You could technically use databinding, but its not recommended at all, because listbox is supposed to used directly from your code according the MSDN documentation.

    On second thought, you could overdraw the listbox and set the item you want to hide to transparent or something, buts its not easy. You may want to consider storing all your values in an array and then loop through array and only adding the elements you want. Or switch to WPF.

    Hope this helps.

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

Sidebar

Related Questions

I want to make a conversation view with ListBox, but I don't know how
How to make the listbox items orientation to horizontal in the default styling of
I would like to make a ListBox function like a Grid . Each time
I'm trying to make a ListBox where highlighted items look the same regardless of
I try to make my ListBox connected to ObservaleCollection be more efficient so for
I am interested in using a onmouseover event to make a listbox appear and
I am trying to make a long ListBox with each ListBoxItem being a tile
Is it possible to make every item of a listbox as a combobox? I
I'm trying to make a style for a listbox which will set the selected
I have a ListBox in a Silverlight Application. I'm trying to make an editable

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.