Binding Format, Parse and Validating Events

J

Joe

Is there anyway to use all 3 of these together? Since Parse doesn't get
called till after Validating I have no way of doing a proper validation
without Parsing the data manually in the Validating event which sort of
defeats the purpose of having a Parse event.

For example:
I have a ComboBox which has one value in the list called "Auto". The
expected value entered by the user will be either "Auto" or an integer or
they can select "Auto" from the dropdown.
"Auto" = 0.

The Format event makes sure that if the value = 0 than "Auto" is displayed
and the Parse event reverses it.

Since Validating is called before Parse the value isn't correct and instead
of it being "Auto" or an integer it could be anything.

Any suggestions?

-Joe
 
R

RobinS

The Parse event is fired after taking the data from the control,
and before moving it to the underlying data source. So the
real purpose of the Parse event is to enable you to change
the data stored. For example, if the user put in a date/time,
and you wanted to convert it to GMT before storing it, you
could use the Parse event to do that. (And use the Format
event to convert from GMT to local time when doing from the
db to the screen.)

You could set up a detached data table, or a generic list,
and bind it to the combo box. Then set DisplayMember to the
text (Auto, 1, 2, 3), and ValueMember to the corresponding
number (0, 1, 2, 3). When they select Auto, you'll get
0 back as the value. Then in the Parse event, you can move
the ValueMember to e.Value to store it in the database.

Robin S.
 
W

WenYuan Wang

Hi Joe

Yes, the parse event doesn't get called till after control's validating
event.
But I don't know why you say you have no way of doing a proper validation
without parsing the data manually in the validation.
Would you mind providing us some code snippet?

However, as Robin said, the real purpose of the parse event is to enable us
to create custom formats for displaying data.
In your case, I think the best solution is that we create a DataTable which
has two columns(one for display, another for value) and set
cobobox.displayMember to displayColumn, set cobobox.valueMember to
ValueColumn.

If there is anything I can help with, please don't hesitate to contact me.
Sincerely,
WenYuan
 
W

WenYuan Wang

Hi Joe,
Just want to check whether there is anything I can help with.
If there is anything I can help with, please don't hesitate to contact me.
We'll go on to assist you on it.

Sincerely,
Wen Yun
 

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