Binding class properties to controls with cancel to prevent editing

G

g18c

Hi, i am very new to data binding and am a little confused!

I have some properties in a class which i would like the user to be
able to edit. I can bind these fields to a control and then show the
form, the user can edit the data in the text boxes and the class's data
members get set ok without any problems.

I do however want to have ok/cancel buttons on the form, which if the
user clicks cancel all changes will be forgotten. now my problem is
with the binding scheme i am using it seems the class's member data
gets set when the text box control looses focus.

I would like to hold of any changes until the user hits ok, whilst at
the same time keeping the capability to check that data entered is
valid and within allowed bounds.

I can always create a copy of the class, bind the form controls to that
class, then check the form result when it returns from being shown and
if i get a DialogResult.OK assign the settings to my class, however im
not sure i can do this as i have socket members etc that will overwrite
my current socket and likely kill the connection which is not what i
want. another way is to keep the class's settings in a seperate
structure and bind that however to me that seems messy. Is there not a
nicer way to achieve this??! Sorry for the newb question, i have spent
a long time searching for an answer and im totaly stuck. Is data
binding even the correct thing for me to use?

Any help much appreciated.

Chris
 
B

Bart Mermuys

Hi,

Hi, i am very new to data binding and am a little confused!

I have some properties in a class which i would like the user to be
able to edit. I can bind these fields to a control and then show the
form, the user can edit the data in the text boxes and the class's data
members get set ok without any problems.

I do however want to have ok/cancel buttons on the form, which if the
user clicks cancel all changes will be forgotten. now my problem is
with the binding scheme i am using it seems the class's member data
gets set when the text box control looses focus.

In NET1.1 the values are pushed to the datasource when validation occurs
(that is, if the control supports validation events).

I would like to hold of any changes until the user hits ok, whilst at
the same time keeping the capability to check that data entered is
valid and within allowed bounds.

I can always create a copy of the class, bind the form controls to that
class, then check the form result when it returns from being shown and
if i get a DialogResult.OK assign the settings to my class, however im
not sure i can do this as i have socket members etc that will overwrite
my current socket and likely kill the connection which is not what i
want. another way is to keep the class's settings in a seperate
structure and bind that however to me that seems messy. Is there not a
nicer way to achieve this??! Sorry for the newb question, i have spent
a long time searching for an answer and im totaly stuck. Is data
binding even the correct thing for me to use?

The PropertyManager(object binding) or CurrencyManager(list binding) that
manages your binding has two methods EndCurrentEdit and CancelCurrentEdit.
But these methods will only work if your object implement IEditableObject,
then your object is responsible for restoring the old values if required.

See link for an example of how to implement IEditableObject (figure5):
http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBind...

I'm uncertain about validating, but if your object implements IDataErrorInfo
it can report errors about invalid property values to the UI.


HTH,
Greetings
 

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