Binding of label text property not behaving as expected.

G

Guest

Folks, I am reading/writing data within an XML file. In my form I have a
label that is assigned to the UpdateDate field within the XML file. Within
the form I update the label to a different date. The code is below. The
issue I'm having is that the DataBinding doesn't seem to be behaving
correctly. The changed value of my "label" is not being written to the file
when AcceptChanges() is called. Instead, the original value from within the
XML file is being written. I noticed that each time I call "AcceptChanges"
that my label is being updated with the original value within the XML file
before the write occurs. The value I placed within the label's text field is
being over-written. Why is this happening?

// This is my XML file.
<?xml version="1.0" standalone="yes"?>
<PlatformDrivers>
<SupportedPlatform>
<Platform>My Computer</Platform>
<CreationDate>7/27/2006</CreationDate>
<UpdatedDate>7/28/2006</UpdatedDate>
</SupportedPlatform>
<Drivers>
<Driver>
<PnPID>VEN_1023&DEV_07A0</PnPID>
<Description>Sample 1 pnp device</Description>
<Version>1.10.A.0</Version>
<Comments>This is a sample of 1</Comments>
<OSSupported>1, 2</OSSupported>
</Driver>
<Driver>
<PnPID>VEN_8988&DEV_1002</PnPID>
<Description>Sample 2 pnp device</Description>
<Version>2.20.B.0</Version>
<Comments>This is a sample of 2</Comments>
<OSSupported>1, 2, 3, 6</OSSupported>
</Driver>
</Drivers>
</PlatformDrivers>


This code binds my lable text property to the field within the XML file.
The value from my XML file (7/28/2006) is correctly shown within my form when
it first pulls up.

this.labelDateModified.DataBindings.Add(new Binding("Text",
this.myDataSet,"SupportedPlatform.UpdatedDate"));


This is where I write the values of my dataset back to the XML file. For
some reason, every time I call AcceptChanges() the label's current value is
being overwritten by the original value within the XML file before the data
is written back to the file. The odd thing is that any changes made within
my DataGridView for the drivers are correctly written to the file. Can
someone tell me why this is happening?

this.xmlDataSet.AcceptChanges();
this.xmlDataSet.WriteXml(this.XmlFilePath());
 
G

Guest

I did more digging and found that I needed to add this line after each of my
binding statements:
this.labelDateModified.DataBinding[0].DataSourceUpdateMode =
DataSourceUpdateMode.OnValidation;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top