Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Itemchanged Event of DataWindow

673 views
Skip to first unread message

Lawrence

unread,
Aug 6, 1998, 3:00:00 AM8/6/98
to
Dear all,

I have a little query over the Itemchanged event of datawindow. Within a
datawindow, I have a number of fields that need to be validated on users'
input. To achieve this, instead of putting my validation function at the
end of the process (i.e. pfc_save) I place it in Itemchanged event of the
datawindow so that once the user types in a value and presses tab key to
lose focus from that field, Itemchanged event will be triggered right away,
hence the validation function will be executed as well. One particular
problem with this operation in Itemchanged event that I found out is, for
instance, a user types in an invalid value in a column field, as the focus
loses the function works perfectly and prompts the user an error message
for re-input as intended. However, assume the user, by mistake, types in
the same value, which of course is invalid, the validation function is not
triggered this time for the reason that the Itemchanged event has not been
triggered at all. That looks absolutely reasonable, how could you expect
the Itemchanged event to perform as the value is exactly the same as the
previous one? It is fine with me. The question is how can I activate my
validation function in Itemchanged event even though there's no change in
value that user has typed in? Or if is there any way to get round this
problem? I'd be pleased to have your valuable suggestions.

Thanks for your kind attention

Lawrence

Larry Cermak[TeamPS]

unread,
Aug 7, 1998, 3:00:00 AM8/7/98
to
>I have a little query over the Itemchanged event of datawindow. Within a
>datawindow, I have a number of fields that need to be validated on users'
>input. To achieve this, instead of putting my validation function at the
>end of the process (i.e. pfc_save) I place it in Itemchanged event of the
>datawindow so that once the user types in a value and presses tab key to
>lose focus from that field, Itemchanged event will be triggered right away,
>hence the validation function will be executed as well. One particular
>problem with this operation in Itemchanged event that I found out is, for
>instance, a user types in an invalid value in a column field, as the focus
>loses the function works perfectly and prompts the user an error message
>for re-input as intended. However, assume the user, by mistake, types in
>the same value, which of course is invalid, the validation function is not
>triggered this time for the reason that the Itemchanged event has not been
>triggered at all. That looks absolutely reasonable, how could you expect
>the Itemchanged event to perform as the value is exactly the same as the
>previous one? It is fine with me. The question is how can I activate my
>validation function in Itemchanged event even though there's no change in
>value that user has typed in?

2 thoughts. In the itemfocuschanged event you could call accepttext
to do validation. Second, in the itemchanged event, if validation
fails, reset the column back to the data retrieved from the db.
Something like
this.SetItem(row,ls_colname,this.GetItemxxx(row,ls_colname,Primary!,true))


Larry Cermak [Team Powersoft] | Moderator forums.powersoft.com.database
Branick Consulting,Inc. | Moderator forums.powersoft.com.powerscript
lce...@branick-inc.com | www.branick-inc.com (PowerBuilder tips & techniques)

Simon Caldwell

unread,
Aug 7, 1998, 3:00:00 AM8/7/98
to
It sounds like you're displaying the error using MessageBox(). Using this
function in the itemchanged event can have unwelcome effects, such as the
one you describe. The way round this is instead of using MessageBox(), use
Modify() to change the column's validation error message, then return 1 to
reject the entered value:

this.Modify("<colname>.ValidationMsg='<your error message>'")
return 1

HTH

Simon

Lawrence wrote in message <01bdc1a7$c498f660$c3e88cca@aslhk>...
>Dear all,


>
>I have a little query over the Itemchanged event of datawindow. Within a
>datawindow, I have a number of fields that need to be validated on users'
>input. To achieve this, instead of putting my validation function at the
>end of the process (i.e. pfc_save) I place it in Itemchanged event of the
>datawindow so that once the user types in a value and presses tab key to
>lose focus from that field, Itemchanged event will be triggered right away,
>hence the validation function will be executed as well. One particular
>problem with this operation in Itemchanged event that I found out is, for
>instance, a user types in an invalid value in a column field, as the focus
>loses the function works perfectly and prompts the user an error message
>for re-input as intended. However, assume the user, by mistake, types in
>the same value, which of course is invalid, the validation function is not
>triggered this time for the reason that the Itemchanged event has not been
>triggered at all. That looks absolutely reasonable, how could you expect
>the Itemchanged event to perform as the value is exactly the same as the
>previous one? It is fine with me. The question is how can I activate my
>validation function in Itemchanged event even though there's no change in

Craig Wagner

unread,
Aug 7, 1998, 3:00:00 AM8/7/98
to
"Lawrence " <law...@asl.com.hk> wrote:

>hence the validation function will be executed as well. One particular
>problem with this operation in Itemchanged event that I found out is, for
>instance, a user types in an invalid value in a column field, as the focus
>loses the function works perfectly and prompts the user an error message
>for re-input as intended. However, assume the user, by mistake, types in
>the same value, which of course is invalid, the validation function is not
>triggered this time for the reason that the Itemchanged event has not been
>triggered at all.

I know you've gotten a couple of responses with suggestions about this problem,
but I don't understand how it's happening in the first place. As a test, I put
the following code in an ItemChanged event of a window built using the demo
database's employee table:

choose case dwo.name
case "emp_lname"
if len (data) < 5 then
MessageBox (parent.title, "Too short.")
Return 1
end if
end choose

I then put the cursor in the emp_lname item and typed 'abc' and hit tab. I of
course got the message "Too short" and the cursor was left in the item. I
deleted the 'abc' that I had typed and typed 'abc' again, and hit tab. Again I
got the message.

So basically, I'm not sure what you could be doing such that it would accept the
same invalid entry the second time around. Not to discount the suggestions
you've been given as 'workarounds', I think there might simply be something
wrong with the way you've coded or used the events.
---
Craig Wagner | E-mail: cwa...@metacorp.com
CPD Professional | Web: http://www.metacorp.com
Certified Powersoft Instructor | Phone: (503) 452-6343
Portland, OR USA |

Keeper of the PowerBuilder FAQ
http://www.teleport.com/~wagnerc/powerbuilder_faq.html

Kaushik Datta

unread,
Aug 7, 1998, 3:00:00 AM8/7/98
to
On Fri, 07 Aug 1998 17:16:24 GMT,
in powersoft.public.powerbuilder.datawindow

Hi Lawrence
What I usually do is define a user event ue_postitemchanged and write
all the validation code in that user event and in the itemchanged event
all I do is PostEvent. Of course with 5.0 onwards, I define the user event
arguments(parameters) same as that of itemchanged event, so that the
default arguments of itemchanged events are available in the user event.
Try this and just drop me a note if it works fine.


Kaushik Datta (http://www.castle.net/~kaudata)

Simon Caldwell

unread,
Aug 10, 1998, 3:00:00 AM8/10/98
to
I'd be surprised if it were the problem here, but I've just (after many
hours!) found that calling RowsCopy from ItemChanged causes the invalid
value to be accepted. My program logic:
- Use Find to see if the new value already exists in the primary buffer
- if it does, then reject it
- if it does not, then call user function uf_find to see if the new value
already exists in the filter buffer. This allows searching in a buffer
other than primary. It works by creating a datastore and using RowsCopy to
put the filter buffer from the dw into the primary buffer of the ds. Then
use Find on the ds.
- if value found in the filter buffer then reject it.

This all works first time. So you key a value that's invalid as it already
exists in the filter buffer. You get a validation error message, and focus
stays in the invalid column. But then hit tab again, and itemchanged
doesn't fire, the offending value has already been accepted.

I eventually found that it was the call to RowsCopy that was causing the
problem, so I amended my code to loop through the filter buffer instead of
using RowsCopy, and this fixed it.

Simon

Craig Wagner wrote in message <35cb3592...@forums.powersoft.com>...

Doug S

unread,
Aug 10, 1998, 3:00:00 AM8/10/98
to
Lawrence wrote:
>
> Dear all,
>
> I have a little query over the Itemchanged event of datawindow. Within a
> datawindow, I have a number of fields that need to be validated on users'
> input. To achieve this, instead of putting my validation function at the
> end of the process (i.e. pfc_save) I place it in Itemchanged event of the
> datawindow so that once the user types in a value and presses tab key to
> lose focus from that field, Itemchanged event will be triggered right away,
> hence the validation function will be executed as well. One particular
> problem with this operation in Itemchanged event that I found out is, for
> instance, a user types in an invalid value in a column field, as the focus
> loses the function works perfectly and prompts the user an error message
> for re-input as intended. However, assume the user, by mistake, types in
> the same value, which of course is invalid, the validation function is not
> triggered this time for the reason that the Itemchanged event has not been
> triggered at all. That looks absolutely reasonable, how could you expect
> the Itemchanged event to perform as the value is exactly the same as the
> previous one? It is fine with me. The question is how can I activate my
> validation function in Itemchanged event even though there's no change in
> value that user has typed in? Or if is there any way to get round this
> problem? I'd be pleased to have your valuable suggestions.
>

Lawerence,
I think the problem is the "bad" data is getting into the buffer and
therefore an itemchanged does not happen twice when the user types the
same value again...try this..on your u_dw control create an instance
variable is_errormsg...in your itemchanged do your validation and if it
fails set is_errormsg = 'field xyz must be less than 100'. then return
1. Now your in the itemerror event....overide and code the following
Integer li_Return
IF is_errormsg > '' then
//check to see if the window is closing if so do NOT show
//the error msg..you'll have to code your own func here
IF NOT parentwindow.YOURFUNCTION_getclosestatus() then
messagebox('your title',is_errormsg)
end if
is_errormsg = ''
li_return =1
Else
li_Return = Super::Event ItemError ( row, dwo, data )
END IF

RETURN li_Return

hth
Doug

Doug S

unread,
Aug 26, 1998, 3:00:00 AM8/26/98
to
Lawrence wrote:
>
> Dear all,
>
> I have a little query over the Itemchanged event of datawindow. Within a
> datawindow, I have a number of fields that need to be validated on users'
> input. To achieve this, instead of putting my validation function at the
> end of the process (i.e. pfc_save) I place it in Itemchanged event of the
> datawindow so that once the user types in a value and presses tab key to
> lose focus from that field, Itemchanged event will be triggered right away,
> hence the validation function will be executed as well. One particular
> problem with this operation in Itemchanged event that I found out is, for
> instance, a user types in an invalid value in a column field, as the focus
> loses the function works perfectly and prompts the user an error message
> for re-input as intended. However, assume the user, by mistake, types in
> the same value, which of course is invalid, the validation function is not
> triggered this time for the reason that the Itemchanged event has not been
> triggered at all. That looks absolutely reasonable, how could you expect
> the Itemchanged event to perform as the value is exactly the same as the
> previous one? It is fine with me. The question is how can I activate my
> validation function in Itemchanged event even though there's no change in
> value that user has typed in? Or if is there any way to get round this
> problem? I'd be pleased to have your valuable suggestions.
>
Lawerence,
I just did a test and I entered an invalid id and our validation routine
in the dw showed me the error and I was forced to either enter a valid
id or blank it out every time that I entered the same value...what value
are you passing on in your itemchanged event when the value fails? You
should return a 1 to not allow focus to change until the user has
entered a correct value or blanked it out. It sounds like your value is
getting set in the primary buffer instead of remaining in the edit
buffer?

hth
Doug

Ken Ewald

unread,
Aug 27, 1998, 3:00:00 AM8/27/98
to
It is best to validate in itemchanged AND at save time.
What if a user changes a value in a column and then clicks on the save icon?
Since they did not tab out of the column, itemchanged will not fire.
I normally functionalize the validation logic for each column and then call
the functions from itemchanged and updatestart.

Doug S wrote in message <35E454...@mmm.com>...

Simon Caldwell

unread,
Aug 28, 1998, 3:00:00 AM8/28/98
to
By default, Update() will trigger an AcceptText, firing validation. The
update is cancelled if the validation fails.
Or perhaps better practice, in the first line of your Save script, put
if dw_1.AcceptText() < 0 then return -1

Simon

Ken Ewald wrote in message ...

Doug S

unread,
Aug 28, 1998, 3:00:00 AM8/28/98
to
Ken Ewald wrote:
>
> It is best to validate in itemchanged AND at save time.
> What if a user changes a value in a column and then clicks on the save icon?
> Since they did not tab out of the column, itemchanged will not fire.
> I normally functionalize the validation logic for each column and then call
> the functions from itemchanged and updatestart.
>
Ken,
The save process should do an accepttext() which will fire an
itemchanged event on the dw control. Not doing so will not apply the
text value into the primary buffer and hence the update will not
include the entered value. Yes, some level of validation is needed at
the itemchanged level,(id entered is valid,min/max values). The save
process should check for required values and then cross reference
validation between columns may be done.

0 new messages