By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,660 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,660 IT Pros & Developers. It's quick & easy.

How to stop a handle being called

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
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" <Niels Je****@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
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

Nov 21 '05 #2

P: n/a
Niels,

The most simple one for your problem is in my opinion to use a switch.

A more direct answer on your question looks for me the Remove and at the end
Addhandler

http://msdn.microsoft.com/library/de...rstatement.asp

I hope this helps

Cor
Nov 21 '05 #3

P: n/a
"Niels Jensen" <Niels Je****@discussions.microsoft.com> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

P: n/a
Hi,

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

Cheers
Niels

"Herfried K. Wagner [MVP]" wrote:
"Niels Jensen" <Niels Je****@discussions.microsoft.com> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.