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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:42:12+00:00 2026-05-19T16:42:12+00:00

I’m storing a whole bunch of settings for my winforms program in various .settings

  • 0

I’m storing a whole bunch of settings for my winforms program in various .settings files.
Included in these settings are System.Drawing.Point, System.Drawing.Location, System.TimeSpan, System.DateTime, etc…

When I bind a form’s Location to a System.Drawing.Location, and call the .Save() method, it all seems to work fine. That is, since there doesn’t seem to be a need for a cast, the form’s System.Drawing.Location is directly compatible with the System.Drawing.Location setting stored in the .settings file.
Additionally, if I say TimeSpan timeSpan = Settings.Duration; that also works fine.

Now, I have made a large settings form, where the user can adjust various parameters, including the various DateTime and TimeSpan settings. These are visible and editable in many TextBox, which I have data bound in the following way:

Settings DefaultSettings = Settings.Default;
TextBox1.DataBindings.Add(("Text", DefaultSettings, "Duration", false, DataSourceUpdateMode.OnValidation, new TimeSpan(00, 30, 00));

The TimeSpan is visible in the TextBox, however when I try to edit it and call Save() on the settings data source, I get the following error:

Value of ‘0’ is not valid for ‘Value’. ‘Value’ should be between ‘Minimum’ and ‘Maximum’.
Parameter name: Value

The error originates from the Visual Studio generated code block:

[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("00:30:00")]
public global::System.TimeSpan StartWorkDay {
  get {
    return ((global::System.TimeSpan)(this["Duration"]));
  }
  set {
    this["Duration"] = value;
  }
}

I think the problem is caused by the fact that it’s trying to turn a string into a System.TimeSpan, and the various other classes I have in my .settings file.

Since I’m binding them using the DataBindings.Add( which accepts strings for the parameters, I can’t cast or use the new keyword there.

I could handle it all manually in code: updating the settings file by constructing the objects parameter-by-parameter, but I have so many settings stored in so many TextBoxes and NumericUpDowns that I would prefer to just bind them straight to the TextBox, assuming that’s possible.

What is the easiest way I can achieve this?

  • 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-19T16:42:13+00:00Added an answer on May 19, 2026 at 4:42 pm

    I tried the following code in a sample windows form application and it did the save without any exceptions.

    // Define the settings binding source
    private System.Windows.Forms.BindingSource settingsBindingSource;
    
     private void InitializeComponent()
      {
                this.components = new System.ComponentModel.Container();
                this.durationTextBox = new System.Windows.Forms.TextBox();
                this.settingsBindingSource = new BindingSource(this.components);
                this.settingsBindingSource.DataSource = typeof(WindowsFormsApplication1.Properties.Settings);
                this.durationTextBox.DataBindings.Add(new Binding("Text", this.settingsBindingSource, "Duration", true));
      }
    
    // In the form load event where the textbox is displayed
    private void Form1_Load(object sender, System.EventArgs e)
    {
       settingsBindingSource.DataSource = Settings.Default;
    }
    
    // save button click
    private void button1_Click_1(object sender, System.EventArgs e)
    {
       // This saved the settings, without any exceptions
       Settings.Default.Save();
    }
    

    Hope it helps.

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

Sidebar

Related Questions

I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have thousands of HTML files to process using Groovy/Java and I need to
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to loop through a bunch of documents I have to put

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.