471,339 Members | 1,281 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

Binding property with CancelCurrentEdit

Hi,

I have a text control bound to a column that is of type Decimal. I am doing
the validation myself to see if the user typed in something invalid, calling
CancelCurrentEdit and cancelling the validation event.

If the user typed in something that is not a number, such as 'abc', then
doing this works. The old value stored in the data source is popped into the
control.

However, if the user typed in something that is a legal number, but outside
the set of legal values as I have determined, and I try the exact same
thing, the data source retains the old value, but the control is not
refreshed to match the datasource. So if the user types in '11', but due to
business rules this is invalid, and I would like to cancel the edit, the
datasource retains it's previous value, but the input control on the screen
still says '11'.

What is going on here?

Any ideas on how to fix this? Other then manually changing the text of the
control, which I would like to avoid since it will mean reparsing the item,
and committing it as a change to the row - when in fact no change took
place.
Jul 21 '05 #1
11 1881
Marina,

You know that I gladly like to help especially you.

However you are for me very mystorious about the type of control.
I get the idea it is a windowsform datagrid, however I am not sure.

Cor
Jul 21 '05 #2
:) Thanks

I said it was a text control. It happens to be an infragistics
UltraTextEditor, but I dont' think it is related to it being an infragistics
control, as it would have no concept of me trying to deal with a numeric. I
think it is related to the binding being to a DataColumn the datatype of
which is Decimal.

Basically, if what the user entered cannot be interpreted by .net as a
numeric, CancelCurrentEdit puts the old value in the control. However, if
..net can turn what is typed in as a numeric, CancelCurrentEdit leaves it
there for some reason.

Any insights?

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Marina,

You know that I gladly like to help especially you.

However you are for me very mystorious about the type of control.
I get the idea it is a windowsform datagrid, however I am not sure.

Cor

Jul 21 '05 #3
Marina,

I ask this because I don't hear you speaking about the binding events, which
seems to me very easy for the problem you describe.

I assume you know them, however you never know.

When you use normal single databinding with the bindingmanager and not a
kind of repeater than you can do everything with it.

http://msdn.microsoft.com/library/de...ventsTopic.asp

When you know this already, than I go another route, however when I had not
showed it than it would have been a waste. I have seen more people long time
active in this newsgroups who never saw them until I showed them. (you have
to push on format and parse to see the documentation).

Cor
Jul 21 '05 #4
Yes, I am handling those 2 events already.

In the Parse, I am keeping track of whether or not the value is acceptable.
The value may be unacceptable because it cannot be parsed to a numeric, or
because it is simply a business rule that is making the value not valid.

In the Validate event for the control, I am checking this saved status. If
the value is good, I call EndCurrentEdit. Otherwise I call CancelCurrentEdit
and say e.Cancel=True, to cancel the event and keep the user in the textbox.

Now, if the status of the parse is invalid due to the string not being
parsed to a numeric, CancelCurrentEdit replaces the old value in the
control. If it is due to a business rule, CancelCurrentEdit leaves the
original value in the datasource, but also leaves the 'bad' value in the
control, instead of putting the datasource's value in the control.

Is that a better explanation of my issue?

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Marina,

I ask this because I don't hear you speaking about the binding events,
which seems to me very easy for the problem you describe.

I assume you know them, however you never know.

When you use normal single databinding with the bindingmanager and not a
kind of repeater than you can do everything with it.

http://msdn.microsoft.com/library/de...ventsTopic.asp

When you know this already, than I go another route, however when I had
not showed it than it would have been a waste. I have seen more people
long time active in this newsgroups who never saw them until I showed
them. (you have to push on format and parse to see the documentation).

Cor

Jul 21 '05 #5
Marina,

A little bit to complex now :-)
I think I do this tomorrow.
When you found it, can you message that than?

Cor

In the Parse, I am keeping track of whether or not the value is
acceptable. The value may be unacceptable because it cannot be parsed to a
numeric, or because it is simply a business rule that is making the value
not valid.

In the Validate event for the control, I am checking this saved status. If
the value is good, I call EndCurrentEdit. Otherwise I call
CancelCurrentEdit and say e.Cancel=True, to cancel the event and keep the
user in the textbox.

Now, if the status of the parse is invalid due to the string not being
parsed to a numeric, CancelCurrentEdit replaces the old value in the
control. If it is due to a business rule, CancelCurrentEdit leaves the
original value in the datasource, but also leaves the 'bad' value in the
control, instead of putting the datasource's value in the control.

Is that a better explanation of my issue?

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Marina,

I ask this because I don't hear you speaking about the binding events,
which seems to me very easy for the problem you describe.

I assume you know them, however you never know.

When you use normal single databinding with the bindingmanager and not a
kind of repeater than you can do everything with it.

http://msdn.microsoft.com/library/de...ventsTopic.asp

When you know this already, than I go another route, however when I had
not showed it than it would have been a waste. I have seen more people
long time active in this newsgroups who never saw them until I showed
them. (you have to push on format and parse to see the documentation).

Cor


Jul 21 '05 #6
Ok.

I can fix this, if after CancelCurrentEdit, I just replace the text of the
control with whatever is in the datasource. It just seems like I shouldn't
have to in this case.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uA**************@TK2MSFTNGP09.phx.gbl...
Marina,

A little bit to complex now :-)
I think I do this tomorrow.
When you found it, can you message that than?

Cor

In the Parse, I am keeping track of whether or not the value is
acceptable. The value may be unacceptable because it cannot be parsed to
a numeric, or because it is simply a business rule that is making the
value not valid.

In the Validate event for the control, I am checking this saved status.
If the value is good, I call EndCurrentEdit. Otherwise I call
CancelCurrentEdit and say e.Cancel=True, to cancel the event and keep the
user in the textbox.

Now, if the status of the parse is invalid due to the string not being
parsed to a numeric, CancelCurrentEdit replaces the old value in the
control. If it is due to a business rule, CancelCurrentEdit leaves the
original value in the datasource, but also leaves the 'bad' value in the
control, instead of putting the datasource's value in the control.

Is that a better explanation of my issue?

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Marina,

I ask this because I don't hear you speaking about the binding events,
which seems to me very easy for the problem you describe.

I assume you know them, however you never know.

When you use normal single databinding with the bindingmanager and not a
kind of repeater than you can do everything with it.

http://msdn.microsoft.com/library/de...ventsTopic.asp

When you know this already, than I go another route, however when I had
not showed it than it would have been a waste. I have seen more people
long time active in this newsgroups who never saw them until I showed
them. (you have to push on format and parse to see the documentation).

Cor



Jul 21 '05 #7
Marina,

Can a datarow.rejectchanges not be the answer on your question.
(First copied to get the changed values).

http://msdn.microsoft.com/library/de...angestopic.asp

Just an idea.

Cor
Jul 21 '05 #8
No, that doesn't work.

For example, let's say the column starts out at the value 2. Then, someone
enters a 5. This is valid. Before saving the row, the user goes in and
enters 11. Now, 11 is not a valid value. Calling
RejectChanges, sets the value back to 2, instead of back to 5.

The desired behavior, would be for the value to go back to 5. And I can't
call AcceptChanges in between, as then the row would get a state of not
modified, and there would be no way to tell there were any changes to the
row.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ur**************@TK2MSFTNGP14.phx.gbl...
Marina,

Can a datarow.rejectchanges not be the answer on your question.
(First copied to get the changed values).

http://msdn.microsoft.com/library/de...angestopic.asp

Just an idea.

Cor

Jul 21 '05 #9
Marina,

I readed it again.

What you want seems to be for me that you want to do the binding again, so
that the correct values from the source are in your control after that all
validating is done and you have corrected the datasource accoording to that.

Is that correct?

Cor
Jul 21 '05 #10
Right.

It does it on its own if the bad value cannot be interpreted as a numeric at
all. But if the value is bad because business rule determine so, then the
control behaves differently.

This is the part I don't understand. The exact same code is executing - just
what the user typed in is different.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:us**************@TK2MSFTNGP10.phx.gbl...
Marina,

I readed it again.

What you want seems to be for me that you want to do the binding again, so
that the correct values from the source are in your control after that all
validating is done and you have corrected the datasource accoording to
that.

Is that correct?

Cor

Jul 21 '05 #11
Marina,

I thought that your answer would have been. I have already removed the
binding and added it again.

:-)

Cor
Jul 21 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Scott Mueller | last post: by
11 posts views Thread by Rourke Eleven | last post: by
19 posts views Thread by Simon Verona | last post: by
reply views Thread by Larry Serflaten | last post: by
6 posts views Thread by Mikus Sleiners | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.