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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:24:49+00:00 2026-06-10T20:24:49+00:00

I have following piece of code: private void nameTextBox_Leave(object sender, EventArgs e) { var

  • 0

I have following piece of code:

private void nameTextBox_Leave(object sender, EventArgs e)
{                  
    var names = ConfigurationManager.AppSettings.AllKeys
                        .Where(k => k.StartsWith("name"))
                        .ToArray();

    // Add names to combobox
    comboBox.Items.AddRange(names);
}

Problem is each time I press Tab from textbox, comboBox elements keep on doubling. If it had Ken, John, Tim in there, it will show that twice if I press tab again.

I tried using distinct in the names above but that does not do anything as new instantance is created each time and previous is saved. I cannot make comboBox empty right after adding names as it is being used in a button click latter on in the code.

Only alternative i thought was of declaring a global variable and make sure its value is 0
and then only insert values in comboBox, and change it to 1 once value is inserted. But that does not seem like a good coding practice.

Is there any better way to get this done?

  • 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-10T20:24:50+00:00Added an answer on June 10, 2026 at 8:24 pm

    Add comboBox.Items.Clear() before the AddRange. So the whole block should be.

    private void nameTextBox_Leave(object sender, EventArgs e) 
    {                   
        var names = ConfigurationManager.AppSettings.AllKeys 
                            .Where(k => k.StartsWith("name")) 
                            .ToArray(); 
    
        // Add names to combobox 
        comboBox.Items.Clear();
        comboBox.Items.AddRange(names); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code in my Silverlight project: private void button1_Click(object sender,
I have the following piece of code: private Dictionary<object, object> items = new Dictionary<object,
I have the following piece of code: class Student { public: Student(){} void display()
I have following piece of code: class Test{ private: int id; public: Test(int v):id(v)
I have following piece of code: customObject* object; std::list<customObject> objects; for(int i = 0;
Here's what I want to do. I have the following piece of code: Private
I have following piece of code: It compiles without problems under gcc-3.4, gcc-4.3, intel
I have following piece of code : public Hashmap<String,String> tempmap = new HashMap<String,String>(); and
I have the following piece of code that takes in some words, stores them
I have the following piece of code in my Model: public function getSite() {

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.