473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to stop a handle being called

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
4 1496
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Bennett | last post by:
Does the .NET framework (using VB.NET) support the ability to programmatically STOP a device prior to its removal from the system? I have need to move data from a computer on one network to a...
2
by: Simon Niederberger | last post by:
Hi I've written a Windows Service which has - several (0-100) listeners threads which spawn worker threads based on events, timers etc - several (0-300) worker threads which handle data...
7
by: Tony Johansson | last post by:
Hello!! Assume I have a handle body pattern with classes called Handle and Body. In the Body class I store one int value for example 7 or some other integer value. In the Handle class I have...
11
by: Frank Rizzo | last post by:
Hello, My c# based windows service takes a while to dispose. I have to release bunch of resources all over the place and unfortunately it can take 20-40 seconds before I can cleanly exit. ...
1
by: Prasad | last post by:
Hi, I am writing a service which takes a long time to stop after the OnStop call is given by the Services Snap-in. The problem is I cannot cut down on the time that it takes to Stop. The Service...
7
by: Denise | last post by:
I just realized the DataTable_RowChanging events were firing when I called Fill method of the DataAdapter! It fires TWICE for each row loaded. I thought these were only supposed to be called when...
51
by: Hans | last post by:
Hi all, Is there a way that the program that created and started a thread also stops it. (My usage is a time-out). E.g. thread = threading.Thread(target=Loop.testLoop) thread.start() ...
7
by: shai | last post by:
I am working at .net 1.1, writing in c#. I have windows service with a COM object. Every unexpected time The COM object throw an error that make my service get stuck (do not respond). I can catch...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.