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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:52:39+00:00 2026-06-09T20:52:39+00:00

I have a ParameterItem class for adding some items to a listbox: class ParameterItem

  • 0

I have a ParameterItem class for adding some items to a listbox:

class ParameterItem
{
    public string Name { get; set; }
    public string Value { get; set; }

    public ParameterItem(string name, string value)
    {
        Name = name;
        Value = value;
    }

    public override string ToString()
    {
        return Name + " = " + Value;
    }

    public override bool Equals(object obj)
    {
        if (obj is ParameterItem)
            return (Name == ((ParameterItem)obj).Name);

        return false;   
    }

    public override int GetHashCode()
    {
        return Name.ToLowerInvariant().GetHashCode();
    }
}

And you can add items to the listbox using two textboxes (name and value). When you click on an item in the listbox, the textboxes get filled with the name and the value of the ParameterItem. I have the following code to change the contents of the selected ParameterItem in the listbox:

    private void btnSaveParameter_Click(object sender, EventArgs e)
    {
        ParameterItem currentParameter = new ParameterItem(textParameterName.Text,
                                                           textParameterValue.Text);
        // If we already have the parameter set then edit it.
        if (lstbxSetParameters.Items.Contains(currentParameter))
        {
            ((ParameterItem)lstbxSetParameters.SelectedItem).Value = currentParameter.Value;
            lstbxSetParameters.;
        }
        // If it's not set yet then add it to the listbox.
        else
        {
            lstbxSetParameters.Items.Add(currentParameter);
            textParameterName.Text = String.Empty;
            textParameterValue.Text = String.Empty;
        }
    }

The problem is, even though I can change the contents of the selected ParameterItem, in the listbox, it still looks like it is not changed.

For example I have a parameter in the list box:

TestParameter = 10

And I change the ParameterItem to

TestParameter = 5

but in the listbox it still looks like

TestParameter = 10

even though it’s been changed.

How can I solve this problem? I think the listbox item should call the ToString() method of the ParameterItem again and refresh itself but how?

Or is there a better way to add key value pairs in the listbox?

  • 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-09T20:52:40+00:00Added an answer on June 9, 2026 at 8:52 pm

    You can change the selected item by remove it and insert it again.

    // If we already have the parameter set then edit it.
    if (lstbxSetParameters.Items.Contains(currentParameter))
    {
        var newItem = new ParameterItem((lstbxSetParameters.SelectedItem as ParameterItem).Name, currentParameter.Value);
        var index = lstbxSetParameters.SelectedIndex;
        lstbxSetParameters.Items.RemoveAt(index);
        lstbxSetParameters.Items.Insert(index, newItem);
        lstbxSetParameters.SelectedIndex = index;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parameterized class. I would like to get the name of the
Given the following class definitions: public class BaseClass { public string SomeProp1 { get;
We have the following class public class TemporalData<T> { private T data; private String
I have a class where one of the public methods is a perfect fit
So I have something like the following: public class Enclosing<T extends Comparable<T>> { //
I have the following class structure: public abstract class Generic<T extends SuperClass> public class
I have a code like this: protected <T> T doSomething(String someParam, Class<T> clazz) {
I have a generic interface: public interface DAO<T> { public T get(long id); public
Suppose I have a LimitedValue class which holds a value, and is parameterized on
I have the following inline Comparator. private static class SampleSorter implements Comparator<SampleClass>{ public int

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.