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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:37:03+00:00 2026-05-24T04:37:03+00:00

I’m writing a .NET 4.0 WinForms app to configure a hardware device. For the

  • 0

I’m writing a .NET 4.0 WinForms app to configure a hardware device. For the sake of example, let’s say that the device has 10 settings that can be configured. The device can also store 5 different configurations. So I’ve created a configuration object that defines the 10 settings. In my form’s constructor, I’m creating an array of 5 configuration objects and setting that array as the datasource for a combobox. The user will select a configuration from a combobox (dropdownlist) and the settings for that configuration will be displayed in the UI. When the user selects a different configuration via the combobox, I need to make sure that all of the settings in the UI have been updated in the current configuration object before I display the settings for the newly selected configuration object. I’m currently doing this in the SelectedIndexChanged event handler for the combobox. When the user is done changing settings, they click a button which will write all five configurations to the hardware device. Here’s where the problem lies. If, for example, they select the third configuration, change some settings in the UI and then click the write button, the settings stored in the third configuration object haven’t been updated yet so the settings reflected in the UI will not be what gets written to the device. I’ve thought of a couple of ways to resolve this:

  1. In the Click event for the write settings button, I could write new code that would always update the data in the appropriate configuration object with the current settings in the UI before writing the data for all five configurations to the device.

  2. In the Click event for the write settings button, I could programmatically set the SelectedIndex value for the combobox to its current value thereby triggering the SelectedIndexChange event handler which would cause the settings to be written to the configuration object before being redisplayed. Then I could write all of the configurations to the device.

I think either would work with perhaps the biggest difference being writing new code for #1 vs. triggerring an existing event handler which already contains the functionality that I need for #2. The more I think about this, though, the more I wonder what is generally regarded as the “correct” way to do something like this. Does anyone have any thoughts or ideas on this? Thanks very much!

  • 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-24T04:37:04+00:00Added an answer on May 24, 2026 at 4:37 am

    It sounds like you aren’t using a BindingSource and you might be doing more work than you need to do.

    When using databinding in WinForms, you usually shouldn’t need to use most of the events you mentioned to accomplish typical requirements.

    For a start, if you aren’t familiar with BindingSource, read up on that.

    This is how you should have it set up:

    • In the forms designer, create a new DataSource from your Configuration class (the one with the 10 settings).

    • Add a BindingSource component to the form.

    • Set the DataSource property of the BindingSource to the new DataSource you just created.

    • Set the ComboBox DataSource to the BindingSource.

    • Set the ComboBox DisplayMember to the appropriate descriptive property of the BindingSource (which now represents the settings class).

    • Bind the Text properties of the 10 TextBoxes to the 10 settings properties of the BindingSource.

    • At runtime, set the DataSource property of the BindingSource to the array containing the 5 configuration objects.

    At this stage you have working databinding. Use the UI to make changes to some of the settings and the changes will be reflected in the datasource (your array).

    (If it doesn’t work or behaves strangely, you may need to remove the event handling you’re currently doing.)
    Note that you do not need to write ANY code so that changes that the user makes are written into your datasource. That happens automatically. You just need to write the code to persist the data somewhere.

    By default, each setting change will only be reflected in the array when the textbox loses focus and another control which has CausesValidation = true gains focus. So if your “write settings” button has CausesValidation = true (which is the default), then your array will contain all the up-to-date data when you handle that click event.

    If you prefer you can have any changes made to the settings textboxes reflected immediately in the datasource by changing the UpdateMode of the bindings to OnPropertyChanged. The default is OnValidation, which means not until the the focus moves to another control with CausesValidation = true.

    One more thing and then I’m going to stop for now (because I know I might be telling you everything you already know):

    Consider making your Settings class implement INotifyPropertyChanged. You can then handle the PropertyChanged event to perform validation as the user enters changes. Alternatively you can handle the Validating events on the controls.

    If you already know all of the above then I apologize for making the wrong assumption. From your question I get the impression that you haven’t fully discovered WinForms databinding yet.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
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

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.