Note that there are some explanatory texts on larger screens.

plurals
  1. POWinforms .Net Simple Databinding Not Working
    primarykey
    data
    text
    <p>I have a Winform with a very basic premise: modify 2 string properties of an object that is passed into it, then save it to disk when the form closes. I am trying to use databinding to bind the Text properties of 2 textboxes on the form to the 2 string properties of the object.</p> <p>But it isn't working. The textboxes never display the values I am assigning to the object properties in the constructor. And when I type something into the textboxes, the object properties are not getting updated. What am I doing wrong?</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Xml; using System.Xml.Serialization; namespace Eds_Viewer { public partial class EdsConfigForm : Form { public EdsConfigForm(EdsConfig myconfig) { InitializeComponent(); EdsConfig = myconfig; if (EdsConfig.VFPConnectionString == null) //set a default value { EdsConfig.VFPConnectionString = "Provider=vfpoledb;Data Source=g:\\eds\\"; } if (EdsConfig.VFPFileName == null) //set a default value { EdsConfig.VFPFileName = "InvoiceDB"; } this.VFPConnectionStringTextbox.DataBindings.Add("Text", EdsConfig, "VFPConnectionString"); this.VFPFileNameTextbox.DataBindings.Add("Text", EdsConfig, "VFPFileName"); } EdsConfig EdsConfig; private void SaveConfigToDisk(EdsConfig myconfig) { XmlSerializer x = new XmlSerializer(typeof(EdsConfig)); TextWriter tw = new StreamWriter("EdsConfig.xml"); x.Serialize(tw, myconfig); tw.Close(); } private void EdsConfigForm_FormClosing(object sender, FormClosingEventArgs e) { this.SaveConfigToDisk(this.EdsConfig); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload