How refresh field with expression on Winform

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

I have a Winform with 3 fields on it, Fields A, B & C. One of them (C) is a
numeric type field that contains an expression. The formula for that field
FieldA * FieldB. The formula works but I don't see the results of the
expression until I update the form. I think this is because prior to doing
the update I do an EndCurrentEdit which forces the refersh.

I would really like to see the expression change as the user makes a change
in field A or B. How would I do this? In what event would I place the
code? I suppose I would want to do something other than and EndCurrentEdit,
if so, what would it be?
 
Hi Woody,
Very quick sommething like this
\\\\\\
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
calc()
End Sub
Private Sub TextBox2_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyUp
calc()
End Sub
''''''''''Just as example
Private Sub calc()
If IsNumeric(Me.TextBox2.Text) And IsNumeric(Me.TextBox1.Text) Then
If CDbl(Me.TextBox1.Text) > 0 And CDbl(Me.TextBox2.Text) > 0
Then
Me.TextBox3.Text = (CDbl(Me.TextBox2.Text) *
CDbl(Me.TextBox1.Text)).ToString
End If
End If
End Sub
/////
Hope this helps
Cor
Cor
 
In the message above there was a typo. The third sentence should read "The
formula for that field is FieldA * FieldB.

I'm sorry to be so convoluted in my question but to cut to the chase. I
have things working the way I want them but I wonder if I am doing it in the
way that VS (and the programmers of this newsgroup) think is orthodox. I
solved my problem by putting the code below in the Validated event for
fields A & B:

Me.BindingContext(DsMain1, "FinSmry").EndCurrentEdit()

Now the expression in Field C gets calculated in real time as I move from
field to field but I would guess that there is a better or different way of
telling the application to change the value in the expression field as I
move from fields that effect the expression. Is there?



Anyone?
 
Hi Woody,

I agree with Cor that we can modify the textbox in other textbox' Keypress
or Textchanged event. This will make value displayed correctly at runtime.
Did you tried this?

AS I understand, you may want the filed C changed aumatically.
Unforturenately, we need to set the value manually if without
EndCurrentEdit.

Does this answer your question?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
I created a simple example to demonstrate how to do this use the Model-View
separation pattern can be used in Object-oriented programming. Download the
DerivedValue zip (VB) from http://home.swbell.net/gar-car/sourcecode.html .
There are some things you should note:
1. The changes to the model object (OrderItem) are automatically handled by
the binding mechanism (see the view initialization).
2. The model object has no knowledge of how it is being displayed, so it can
be reused in any program that needs this capability.
3. The model object (OrderItem) contains the "business logic" (in this case
multiplying two fields to generate a result), so the GUI is completely
"throw-away" without any loss of the "business logic".

I didn't do any validation of inputs, but this is easily handled.
Let me know what you think.

Gary
 
Back
Top