How to stop a handle being called

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm a bit of a newbie to VB.NET so please forgive me if I get the
terminology incorrect... I'm still learning :)

I have a form with five numUpDown controls representing different ratios for
5 diferent things. Next to them are 5 checkboxes that can be used to lock
it's relevant ratio. I'm trying to get them to automatically distribute a
total of 100 amongst themselves. I've managed to get this working - almost...

The process I have is that when a user changes a value in one of the
numUpDown controls, the .OnChange handle for that control calls a method that
calculates the new values for the remaining 4 NumUpDown controls and updates
them.

The problem I have, is that because the same method is used by all the
NumUpDown controls using the .OnChange handle then when one of the Controls
changes the ratios and updates the values in the remaining 4 controls then
their .OnChange handles are called and they automatically reset the value of
the original changed control. I hope this makes sense.

So is there any way to change a value in a control and then stop it's
OnChange Handle from calling a method?

Cheers

Niels
 
Hi Niels,

I would do this in the following way:

Private Calculating As Boolean

Private Sub NumericUpDown1_ValueChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NumericUpDown1.ValueChanged,
NumericUpDown2.ValueChanged
If Not Calculating Then
Calculating = True
CalculateOthers(CType(sender, NumericUpDown))
Calculating = False
End If
End Sub

Private Sub CalculateOthers(ByVal Sender As NumericUpDown)
'calculate the values of the other controls
If ReferenceEquals(Sender, Me.NumericUpDown1) Then
Me.NumericUpDown2.Value = 100 - Me.NumericUpDown1.Value 'could be
any calculation of course
Else
Me.NumericUpDown1.Value = 100 - Me.NumericUpDown2.Value 'could be
any calculation of course
End If
End Sub

Hope this helps
Stefan
 
Niels Jensen said:
I have a form with five numUpDown controls representing different ratios
for
5 diferent things. Next to them are 5 checkboxes that can be used to lock
it's relevant ratio. I'm trying to get them to automatically distribute a
total of 100 amongst themselves. I've managed to get this working -
almost...

The process I have is that when a user changes a value in one of the
numUpDown controls, the .OnChange handle for that control calls a method
that
calculates the new values for the remaining 4 NumUpDown controls and
updates
them.

The problem I have, is that because the same method is used by all the
NumUpDown controls using the .OnChange handle then when one of the
Controls
changes the ratios and updates the values in the remaining 4 controls then
their .OnChange handles are called and they automatically reset the value
of
the original changed control. I hope this makes sense.

\\\
Private m_CalledByCode As Boolean
..
..
..
Public Sub NumericUpDown1_...(...) Handles...
If Not m_CalledByCode Then
...
End If
End Sub
..
..
..
m_CalledByCode = True
SetOtherNumericUpDownControls()
m_CalledByCode = False
///
 
Hi,

Thanks for the help guys - I'll have a look at what I can do with your advice

Cheers
Niels
 
Back
Top