473,385 Members | 1,727 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 disable the numericupdown event firing?

Hello,

A probably dumb question...

does anyone know hot to avoid that if one keep the mouse pressed on an
arrow of the numericUpDown it continues to fire events (it uses
evidently a timer) ?

I want 1 event for each click, and no timer activation. I have tried
using disable within the handler but does not work.

Any idea?

tommaso

May 10 '06 #1
16 9127
I assume you do not want the SelectedIndexChanged event to only fire
once? Why not create a Boolean property in the Form's class, and
manipulate it with the MouseDown and MouseUp events to indicate the
state of the mousebutton. Then the SelectedIndexChanged event can check
this property and if set, exit.

May 10 '06 #2
hi!
thanks for the reply.
Checking mouse event can't do it, IMHO, as the mouse can ble clicked
out of the arrows, unless one knows how to detect that (?).

(I am not sure what you mean by "SelectedIndexChanged ": I am using VB
2005 and I do not have this event for the "NumericUpDown". Perhaps you
meant another control...).

Any other ideas?

-tommaso

May 10 '06 #3
I was talking aout the MouseUp and MouseDown events for the numeric
updown control, which fire ONLY when you click on the numeric updown
controls buttons.

May 10 '06 #4
I have used the NUD control and it most certainly has a
SelectedIndexChanged event, which I use to change the value displayed
in a related textbox. If you are not using any of the NUD's events, I
don't see what your problem is.

May 10 '06 #5
mmm, well there must be some misundertunding here.

I have just tried and the MouseDown and MouseUp events are raised even
if you do not click on the arrows of the NumericUpDown.
Further I am not able to find the "SelectedIndexChanged" for the
NumericUpDown. Could you provide a pointer to the documentation where
it is dealt with?

At this point I am a little bit confused. I still think we are talking
about different things (perhaps you talk about a ComboBox ??)...

tommaso

May 10 '06 #6
Sorry, my bad. Not SelectedIndexChanged, ValueChanged.

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/CPref17/html/E_System_Windows_Forms_NumericUpDown_ValueChanged. htm

And you are right, to a degree. The MouseDown and MoustUp event do fire
if the mouse is simply somewhere over the control and the mouse button
is clicked, not when you click on one of the control's up or down
buttons. There may be some way to use them with the ValueChanged event
or some other event to accomplish your desired result.

May 10 '06 #7
Yes. Let me explain further my problem, which actually I believe is a
BUG of the numericUpDown control which was already present in version
2003, and the VS team does not *seem* to have done anything about it.

ANYTIME you place any code under the ValueChanged event which take a
little while to execute (I do not mean a very long process [which could
justify for instance a new thread], but something within tens of a
second), if you keep the mouse clicked on one arrow you systematically,
that is ALWAYS get the following error:

----------------------------
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="System.Windows.Forms"
StackTrace:
at
System.Windows.Forms.UpDownBase.UpDownButtons.Time rHandler(Object
source, EventArgs args)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndPr oc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext
context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at Trial.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
------------------

and there seems anything one can do about it.

That's why I wished to disable the associated timer. Because it causes
an exception I cannot do anything about.

If anyone has suggestion to solve this annoying problem (and I do hope
someone of the VS team is listening) I would like to know.

tommaso

May 10 '06 #8
Hmm, you know, the app I wrote that uses the NUD control does some
calculations in the ValueChanged event, and I can hold down either the
up or the down button, and I have never (so far) gotten the exception
you get. The calculations are not intense, but are not trivial either.
Maybe I will test it and see if I can re-create your problem.

May 10 '06 #9
It doesn't take much to reproduce the bug. It is crucial (to get the
exception) that
the called routine allows events (DOEVENTS). I get systematically this
exception
when drawing something within the ValueChanged event.

Here is the BUG demo code. Just create a form with a NumericUpDown and
paste the code.
Run the program. Click on the UP arrow and keep pressed. You will get
the exception very soon.
I don't go beyond 11.

'--------------------------------begin code

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.NumericUpDown1.Maximum = Decimal.MaxValue
End Sub

Private Sub NumericUpDown1_ValueChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NumericUpDown1.ValueChanged
Me.SomeTaskWithEvents()
End Sub

Sub SomeTaskWithEvents()
System.Threading.Thread.Sleep(10)
Application.DoEvents()
End Sub

End Class

'--------------------------------end code


- Details

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="System.Windows.Forms"
StackTrace:
at
System.Windows.Forms.UpDownBase.UpDownButtons.Time rHandler(Object
source, EventArgs args)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndPr oc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.DoEvents()
at BUGNUD.Form1.SomeTaskWithEvents() in C:\Documents and
Settings\User\Documenti\Visual Studio
2005\Projects\BUGNUD\BUGNUD\Form1.vb:line 13
at BUGNUD.Form1.NumericUpDown1_ValueChanged(Object sender,
EventArgs e) in C:\Documents and Settings\User\Documenti\Visual Studio
2005\Projects\BUGNUD\BUGNUD\Form1.vb:line 8
at System.Windows.Forms.NumericUpDown.OnValueChanged( EventArgs
e)
.....

May 10 '06 #10
In the mouse down event, use the "Remove Handler" to remove the ValueChanged
Event handler then in the MouseUp event, use the Add Handler to restore event
handling in the Value Changed Event. This should work.
--
Dennis in Houston
"to**************@uniroma1.it" wrote:
It doesn't take much to reproduce the bug. It is crucial (to get the
exception) that
the called routine allows events (DOEVENTS). I get systematically this
exception
when drawing something within the ValueChanged event.

Here is the BUG demo code. Just create a form with a NumericUpDown and
paste the code.
Run the program. Click on the UP arrow and keep pressed. You will get
the exception very soon.
I don't go beyond 11.

'--------------------------------begin code

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.NumericUpDown1.Maximum = Decimal.MaxValue
End Sub

Private Sub NumericUpDown1_ValueChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NumericUpDown1.ValueChanged
Me.SomeTaskWithEvents()
End Sub

Sub SomeTaskWithEvents()
System.Threading.Thread.Sleep(10)
Application.DoEvents()
End Sub

End Class

'--------------------------------end code


- Details

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="System.Windows.Forms"
StackTrace:
at
System.Windows.Forms.UpDownBase.UpDownButtons.Time rHandler(Object
source, EventArgs args)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndPr oc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.DoEvents()
at BUGNUD.Form1.SomeTaskWithEvents() in C:\Documents and
Settings\User\Documenti\Visual Studio
2005\Projects\BUGNUD\BUGNUD\Form1.vb:line 13
at BUGNUD.Form1.NumericUpDown1_ValueChanged(Object sender,
EventArgs e) in C:\Documents and Settings\User\Documenti\Visual Studio
2005\Projects\BUGNUD\BUGNUD\Form1.vb:line 8
at System.Windows.Forms.NumericUpDown.OnValueChanged( EventArgs
e)
.....

May 10 '06 #11
hi Dennis,

MouseUp/Down cannot be used to place semaphores or detach handlers as
they are fired even when the mouse is clicked on an area of the NUD
different from arrows.

Further, the ValueChanged is executed under a handles clause and cannot
be removed that way,...

Could you actually show your suggestion applied to the Bug code?

tommaso

May 10 '06 #12
MouseUp/Down events CAN be used to remove/add handlers. The following works
except that the ValueChanged event is fired ONCE before the mousedown event
is fired when the mouse button is held down.

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles NumericUpDown1.ValueChanged

'Will fire one time when the mouse is pressed and held then not fire
again until the function is called from the MouseUp event.

End Sub

Private Sub NumericUpDown1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles NumericUpDown1.MouseDown
RemoveHandler NumericUpDown1.ValueChanged, AddressOf
NumericUpDown1_ValueChanged

End Sub

Private Sub NumericUpDown1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles NumericUpDown1.MouseUp
AddHandler NumericUpDown1.ValueChanged, AddressOf
NumericUpDown1_ValueChanged
Dim e1 As New System.EventArgs
'NumericUpDown1_ValueChanged(sender, e1)
End Sub
--
Dennis in Houston
"to**************@uniroma1.it" wrote:
hi Dennis,

MouseUp/Down cannot be used to place semaphores or detach handlers as
they are fired even when the mouse is clicked on an area of the NUD
different from arrows.

Further, the ValueChanged is executed under a handles clause and cannot
be removed that way,...

Could you actually show your suggestion applied to the Bug code?

tommaso

May 10 '06 #13
Good! You are right.

You are almost there. There seems to be a last problem. If one clicks
on UpArrow and release the mouse and repeat this process starting, for
instance, from 1, the ValueChanged events is fired only for the odd
numbers. That is in a sequence of clicks only half of them rise the
ValueChanged event. But one would like to get the event for each
click...

Any idea?

tommaso

May 10 '06 #14
mmm, I am afraid that this isn't the right approach. There seems to be
no way to make it work right.
Perhaps another approach could be working by reflection and disabling
the internal timer.
But, It would probably be easier to create a custom NUD!

Such a small control is so defective! I still do not understand how
come takes so long (years) to fix it !

-t

May 10 '06 #15
Here is a stupid workaround which seems to work.

I include a complete demo. Requires a NUD and a CheckBox. Whem the
CheckBox is not checked
the program show the NUD "out of sync" (is that a good name?) BUG, if
checked implements the dumb
workaround to stop continuous event firing (which causes bug).

If you have more suggestions, please let me know. And let's hope that
they fix soon the NUD
this is the kind of things that make Infragistic (and similar business)
happy, I guess !
Public Class Form1

Private DisableFiring As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Text = "NUD BUG Demo"
Me.CheckBox1.Text = "Disable continuous firing"
Me.NumericUpDown1.Maximum = Decimal.MaxValue
End Sub

Private Sub NumericUpDown1_ValueChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NumericUpDown1.ValueChanged
If DisableFiring Then Me.NumericUpDown1.Enabled = False
Me.SomeTaskWithEvents()
If DisableFiring Then NumericUpDown1.Enabled = True
End Sub

Sub SomeTaskWithEvents()
System.Threading.Thread.Sleep(10)
Me.Text = "Value " & Me.NumericUpDown1.Value
Application.DoEvents()
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Me.DisableFiring = Me.CheckBox1.Checked
End Sub

End Class

May 10 '06 #16
Yes, it's too bad they don't fix the ValueChanged event on the NumericUpDown
control. It should fire the ValueChanged event AFTER the Click event which
is fired after the MouseUp event OR have a BeforeValueChange event with a
cancel option. Many of Ms controls are like this. I don't think they put
much thought into their controls...third party controls are much better
normally.
--
Dennis in Houston
"to**************@uniroma1.it" wrote:
Here is a stupid workaround which seems to work.

I include a complete demo. Requires a NUD and a CheckBox. Whem the
CheckBox is not checked
the program show the NUD "out of sync" (is that a good name?) BUG, if
checked implements the dumb
workaround to stop continuous event firing (which causes bug).

If you have more suggestions, please let me know. And let's hope that
they fix soon the NUD
this is the kind of things that make Infragistic (and similar business)
happy, I guess !
Public Class Form1

Private DisableFiring As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Text = "NUD BUG Demo"
Me.CheckBox1.Text = "Disable continuous firing"
Me.NumericUpDown1.Maximum = Decimal.MaxValue
End Sub

Private Sub NumericUpDown1_ValueChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NumericUpDown1.ValueChanged
If DisableFiring Then Me.NumericUpDown1.Enabled = False
Me.SomeTaskWithEvents()
If DisableFiring Then NumericUpDown1.Enabled = True
End Sub

Sub SomeTaskWithEvents()
System.Threading.Thread.Sleep(10)
Me.Text = "Value " & Me.NumericUpDown1.Value
Application.DoEvents()
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Me.DisableFiring = Me.CheckBox1.Checked
End Sub

End Class

May 10 '06 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
7
by: Scott Emick | last post by:
How can I disable events for the controls on a form? I tried setting the form's enable property to false, but that doesn't stop events from firing on its controls. I need to temporarily disable...
3
by: abc my vclass | last post by:
My win-form have many numericupdown controls to applied. But numericupdown control don't like textbox, text box control can automatic selected text when got focus. Is there any method can let me...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.