ViewerLogic: How to detect a value was changed (in Leave-event of the control)
 
Forums / SmartComponent Library - Developer Forum / ViewerLogic: How to detect a value was changed (in Leave-event of the control)

ViewerLogic: How to detect a value was changed (in Leave-event of the control)

3 posts, 0 answered
  1. Pascal Pyck
    Pascal Pyck avatar
    2 posts
    Registered:
    14 Dec 2018
    27 May 2021
    Link to this post
    How can I detect the value was changed in the leave-event of a control on a SmartViewerControl ?
    I placed coding in the "enter event" to store the current value and in the "leave event" I compare the value with the original value.

    Now when a form starts with "ExternalDatasource", the enter of the first field in the viewer happens before the data is present.
    So when leaving the field (tab out of it) the original value isn't stored which means my comparison between orginal and current value always says the value has changed and it fires some code I wrote that only should happen when leaving the field if it has been changed.
  2. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    27 May 2021 in reply to Pascal Pyck
    Link to this post
    What are you trying to solve exactly? 

    If it's validation, Microsoft recommends the use of the Validating or Validated events (more details in the .NET documentation). But shouldn't that be a task for the backend?

    If you want to compare the current value to the original one , you can compare the values in the BindingSource's InputValue dictionary with the Value property of the Infragistics control. Remember to use UNBOX ...

    Or you can call the Data Adapter's GetFieldValue() method to get the value from the temp-table field. 

    If you just need to know the field value was changed, you should relay on the ValueChanged event in combination with checking if the field has Focus and if the ValueChanged was triggered from the BindingSource. There is sample code for that in the SmartViewerControl class. 
  3. Pascal Pyck
    Pascal Pyck avatar
    2 posts
    Registered:
    14 Dec 2018
    27 May 2021 in reply to Mike Fechner
    Link to this post

    I'm trying to propose values for other fields on the viewer.

    F.ex.:
    a viewer with 3 fields
    in the "leave event" of field_1 I have something like this:
    if field has changed
    then do:
        case <CurrentValue>:
        when "a" then field_2:ScreenValue = "one".
        when "b" then field_2:ScreenValue = "two".
        ...
        end case.
    end.

    Case: Enter the viewer:
    - enter "a" in field_1     -> "one" is proposed in field_2
    - tab out of field_1
    - user changes value of field_2 to "test"
    - tab out of the last field of the viewer -> focus becomes on first field of the viewer
    - tab out of field_1 I don't want field_2 to be changed because the user didn't change the value of field_1

3 posts, 0 answered