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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:24:36+00:00 2026-05-31T06:24:36+00:00

I’ve set up a simple form. A ListBox takes values from a list in

  • 0

I’ve set up a simple form. A ListBox takes values from a list in the ‘business object’ displaying the Name property and providing the Value property.

In additon the ListBox’s SelectedItem property is bound to a property in the same business object.

Using the UI to select a value from the list correctly changes the objects property (checked when the button is clicked) and the correct value is available. So far so good.

However, if the ListBox’s SelectedIndex property is changed in the code, then the UI correctly changes as expected but the business property does not change – it would appear to have missed the change event. This is true for both setting in the constructor and in the button event handler (see the code).
What have I missed or what am I doing incorrectly.
(I’ve only included the code I’ve written – not VS wizard generated stuff)

class Frequency
{
    public String Name { get; set; }
    public Int16 Value { get; set; }

    public Frequency(String name, Int16 value)
    {
        Name = name;
        Value = value;
    }
}

class FrequencyList : System.ComponentModel.BindingList<Frequency>
{
}

class Model
{
    public static FrequencyList FrequencyValues = new FrequencyList() 
    {
        new Frequency("Slowest", 100),
        new Frequency("Slow", 150),
        new Frequency("Medium", 1000),
        new Frequency("Fast", 5500),
        new Frequency("Fastest", 10000)
    };

    public Frequency StartFrequency { get; set; }

    public void DoStuff()
    {
        if (StartFrequency == null)
            return;

        Int16 freq = StartFrequency.Value;
    }
}

    public partial class Form1 : Form
{
    private Model myModel = new Model();

    public Form1()
    {
        InitializeComponent();

        // Bind the list to a copy of the static model data
        this.listBox1.DataSource = Model.FrequencyValues;
        // Bind the control to the model value
        this.listBox1.DataBindings.Add("SelectedItem", myModel, "StartFrequency");
        // Select the start value
        this.listBox1.SelectedIndex = 3;

    }

    private void button1_Click(object sender, EventArgs e)
    {
        Int16 f = (Int16)listBox1.SelectedValue;

        this.myModel.DoStuff();
        int new_index = listBox1.SelectedIndex + 1;
        if (new_index >= listBox1.Items.Count)
            new_index = 0;
        listBox1.SelectedIndex = new_index;
    }
}
  • 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-31T06:24:37+00:00Added an answer on May 31, 2026 at 6:24 am

    You don’t want the Click event, you want the SelectedIndexChanged event. This will trigger regardless of whether the user or the program instigates the change.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string

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.