cancel
Showing results for 
Search instead for 
Did you mean: 

Calling the event in another event pb7

Former Member
0 Kudos

Friends...

I am calling the rowfocuschanged event from itemchanged event....but the calling event is not working.

see the italic bold line. the event

dw_2 item changed event.

String ls_PassFail

If dwo.Name = 'marks_final_grade' Then

   Choose Case data   // What is the letter grade?

      Case 'A','B','C','D','E','S'

         ls_PassFail = 'Pass'

      Case 'U'

         ls_PassFail = 'Fail'   

            dw_2.TriggerEvent(rowfocuschanged!)

        case else

            ls_PassFail = 'Nil'

   End Choose

   This.SetItem(row,'marks_final_passfail',ls_PassFail)    

End If

my requirement is....marks_final_passfail field's font color should be red...once the 'Fail' case comes...

already the rowfocuschanged event is working...but now i am not going to that field to select 'Pass' or 'Fail'...iam doing it here...so i want to change the font color also from here(dw_2 item changed event)

thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

why not put an expression for the font color of the column in the DW painter ?

ex: if ( marks_final_passfail = "Fail", 255, 33554432 )

HTH,

Former Member
0 Kudos

sorry...this is not changing the color instead of that its showing the font in a tilted manner.

Former Member
0 Kudos

Maybe I was not clear ...

Could you try this ?

Regards

Former Member
0 Kudos

I suggest you follow Philippe's reply for multiple reasons.

  • You should NEVER refer to an object by name within a script of that object.  Use "this" - as someone else did in the last statement of the IF block. Why?  If you rename the object (or reuse the code somewhere else) the name can change and the code will not compile.
  • You have a logically flawed approach, though your testing has not yet revealed that.  Itemchanged can be triggered under a variety of conditions.  You should not attempt to trigger other GUI/navigation related events just to invoke some special logic that is coded in one since this can cause issues with the GUI itself.  If there is some set of code that needs to be executed in different events, the best approach is to refactor that logic into a separate unit of code and call it from wherever it is needed. Next time you test this, change the value in marks_final_grade column and then <shift+tab> rather than <tab>.  The itemchanged event will be triggered but the GUI should navigate to the previous item.  There should be no change of row (presumably).
  • I would argue that since marks_final_passfail is completely dependent on the value of marks_final_grade that it should not be a column in the datawindow at all.  You could use a computed field to do the same thing - and that requires no GUI code in your datawindow control.


former_member1333806
Active Participant
0 Kudos

If by "tilted" you mean setting that Italic attribute, then Philippe's approach is still an improvement if applied to the expression for the Italic attribute (and changed parameters for the If() function). In fact, done right, his approach should make things simpler and able to handle more cases (e.g. bulk data loading, programmatic change of marks_final_grade). (We're assuming you want this change on a row-by-row basis, which isn't entirely clear from your post.)

BTW, slightly off-topic, but I always considering it very bad design to call a system event directly like that. If someone on my team sees a need for something like that, I have them break the code in question out into a custom user event or function, and fire it from both places. Why?

  1. As Roland points out, people tend to forget to populate system event parameters, or populate them incorrectly.
  2. The next programmer will identify a requirement that could be implemented in the called event (in your case, RowFocusChanged), and have no reasonable reason to expect that he's impacting ItemChanged functionality. Then the code sinks into a morass of flags and tests to trigger this when that happens, and fire this when either happens, etc.... which requires a 50-page treatise for the next programmer to be able to understand. (And we all know how programmers like writing documentation...)
  3. Today it's just one place that needs the call, but tomorrow it's half a dozen others (e.g. bulk data loading, programmatic change of marks_final_grade), and the management of cases described above becomes completely chaotic.

JMHO and my experience.

Good luck,

Terry.

Former Member
0 Kudos

sorry philippe....its not working..

Actually, both the marks_final_grade and marks_final_passfail is a drop down box.

marks_final_grade has dropdown datawindow. and marks_final_passfail..is not from the drop down datawindow. i dont know where i am making mistake...

arnd_schmidt
Active Contributor
0 Kudos

In the expression for marks_final_passfail use the Data Value.

So if 'F' is related to 'Fail':

if ( marks_final_passfail = "F", 255, 33554432 )

hth

Arnd

Former Member
0 Kudos

i have already tried that...its not working...

below is working

dw_2.modify("marks_final_passfail.Color='413200'")

but we have many dropdownboxes as per the above code, all the text of the dropdownboxes inside the datawindow are changing...

i need only the particular dropdownbox/row text color should be changed.

arnd_schmidt
Active Contributor
0 Kudos

There is no need for a dw_2.Modify ()  - If possible just set the expression with the "if" in the DW Painter.

If you want to do this via Modify () you have to add a default value and a  '~t' in front of the expression.

string ls_error

ls_error = dw_2.Modify("marks_final_passfail.Color='" + '0~tif ( marks_final_passfail = "F", 255, 0 )' + "'" )

If Len ( ls_error ) > 0 then MessageBox ("Modify Error" , ls_error )


hth


Arnd

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Sathy;

  I would like to suggest that you change the TriggerEvent ( ) to a PostEvent ( ) method to let the ItemChanged event complete properly first.

Regards ... Chris

Former Member
0 Kudos

Triggering an event with the TriggerEvent function doesn't populate the event arguments. Really it should be coded like this:

dw_2.Event RowFocusChanged(dw_2.GetRow())