Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EditChanged Event do not pass in ItemChanged Event

Status
Not open for further replies.

kcin1234

Programmer
Jun 16, 2011
2
0
0
PH
I have a problem guys and hopefully you can help me.

I write a series of code in the EditChanged Event of my datawindow user object to validate if the character entered is a valid numeric figure. It works fine that the field only accept numeric figures.

--Here is my code in the EditChanged Event
--Start
//Start of variable declarations
Long ll_ctr
Long ll_len
Long ll_pos
Long ll_index

String ls_column
String ls_type
String ls_value
String ls_newvalue
String ls_char
String ls_style
//End of variable declarations

ls_column = this.GetColumnName()
ls_type = this.Describe(ls_column + '.coltype')

If left(ls_type,4) = 'deci' Then

ls_style = this.Describe(ls_column + '.Edit.Style')

If ls_style <> 'dddw' Then
ls_value = String(data)

ll_pos = this.Position()

ll_len = len(ls_value)

If ll_len = 0 Then Return

this.SetItem(row, ls_column, f_removechar(Trim(ls_value)))

this.SetColumn(ls_column)

ls_newvalue = String(this.GetItemDecimal(row, ls_column))
ls_char = Mid(data, ll_pos - 1, 1)
ll_index = Pos(ls_newvalue, '.', 1)

If ll_len > len(ls_newvalue) and ls_char <> "." and ll_pos - 1 <= ll_index Then
this.SelectText(ll_pos - 1, 0)
ElseIf ls_char = "." Then
this.SelectText(ll_pos, 0)
ElseIf ll_len > len(ls_newvalue) and ll_pos > ll_index and IsNumber(ls_char) = False Then
this.SelectText(ll_pos - 1, 0)
Else
this.SelectText(ll_pos, 0)
End If

End If
End If
--End of EditChanged Event code

The function f_removechar is function that will return the valid numeric figures.

What my problem with this code in the EditChanged Event is that after I leave the column it doesn't pass in the ItemChanged Event of the datawindow. I really need to pass in the ItemChanged Event because there are still series of code to be executed but unfortunately they were not entertained.

Kindly help me to figure out this problem.

Thanks for the help.
 
wow you're not afraid!

Itemchanged will only be fired when you move the focus to another column, no while editing the contents of a dw-field.
(unless you do an accepttext() in the editchanged(), but not too sure of that)

I can't give you a solution just like that, but keep something important in mind:
You are doing a getItemDecimal in your code. the value obtained by that will be the unchanged/unedited value, untill the itemCHANGED event has finished.

some people do an AccepText() in the editchanged event to force newly entered data to be in the primary! buffer (the one accesed by GetItem...() ), but this is very ugly programming and likely to cause problems like infinite loops etc.

you might make things easier by putting your code in a new userdefined event / function and call that one from the editchanged event, using POST.

editchanged event:
-----------------
this.event POST ue_myUsereventWhereIPutPreviousCode(..., ....)
It's quite late here and I'm really tired of work, but hope it might help you.

Just in case:
------------
Anyway ... what are you really trying to do?
Has it got something to do with "," and "." as decimal and thousand separators, pending on language settings of windows? A suggestion is to use doubles instead of decimals in your code so you won't have to worry that much about the language settings. (the notation would be always "," for thousands and "." for decimals.

Tell me if I'm missing something



regards,
Miguel L.
 
The purpose of this code is to eliminate non-numeric character except for dot(.) character for decimal purposes during editchanged event. I have the option to use editmask to make it simple but the decimal field should be also AutoSelection. If you have other suggestions how can a decimal field should not accept non-numeric figures and at the same time it is a AutoSelection is deeply appreciated.

---
@Matt
It does not fire in the ItemChanged Event after I changed the value and lose focus in a decimal field.

--
I have tried to isolate the problem and here is what I discovered why it doesn't fire in the ItemChanged event.

This is the series of code I put in the EditChanged Event

--Start of Editchanged event code
String ls_column
Decimal ld_value

ld_value = 2
ls_column = this.GetColumnName()

this.SetItem(row, ls_column, ld_value)

--End of EditChanged event code

Hope this helps. Thanks..




 
the validation you're trying to do should not be done in the editchanged event.
Just use a decimal type input field, check the "autoselect attribute", don't use an editmask (use format: "#,##0.00" for example to make it look good after editing)

and ...

code the ITEMERROR event to intercept errors that would occur when the user enters non-numeric data. (it will be fired automatically in case the data does not comply the inputfield-type without triggering the itemchanged).



regards,
Miguel L.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top