Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

NumericUpDown not saving when Commit

Posted on 2014-01-20
7
Medium Priority
?
1,091 Views
Last Modified: 2014-01-21
Hi experts
I have a numericUpDown control bound to a bindingSource:
nupTest.DataBindings.Add("Value", bindingSource, "Parameter1", true, DataSourceUpdateMode.OnPropertyChanged);

Open in new window

where the bindingSource was bound to an object:
bindingSource.DataSource = anObject

Open in new window


When I typed value directly into the numericUpDown box and did commit edit, the value was not saved.
CommitEditUi.Commit(nupTest);

Open in new window


In order to get it to be saved, I needed to first click off.
Please let me know what I need to do so that I don't need to do the click off.
Thanks
0
Comment
Question by:dominicwong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39798471
I would think that you need to call BindingSource.EndEdit, but I am not sure which event handler you would need to include that in (thinking...)
0
 

Author Comment

by:dominicwong
ID: 39798529
Thanks TheLearnedOne.
I called bindingSource.EndEdit before saving all the object values to a file. But the new value in the numericUpDown Control still didn't pass on the new value.
0
 
LVL 28

Expert Comment

by:Ark
ID: 39798895
This is because you bind "Value" property. According MSDN
For the ValueChanged event to occur, the Value property can be changed in code, by clicking the up or down button, or by the user entering a new value that is read by the control. The new value is read when the user hits the ENTER key or navigates away from the control. If the user enters a new value and then clicks the up or down button, the ValueChanged event will occur twice.
So, bind to Text property or assign Value in TextChanged event handler
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:Ark
ID: 39798943
Just found undocumented future (bug?) for numeric updown - adding dummy TextChange event handler which read Value property DOES fire valuecahenged event.
    Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
        Debug.Print(String.Format("ValueChanged (Text = {0}, Value = {1})", NumericUpDown1.Text, NumericUpDown1.Value))
    End Sub
    'Private Sub NumericUpDown1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.TextChanged
    '    Dim x = NumericUpDown1.Value
    'End Sub

Open in new window

Run sampel with commented TextChanged handler and type in NumericUpDown - nothing printing in the debug window. Uncomment handler and type again - you'll see ValueChanged event fired! So just add dummy handler to your code"
Private Sub nupTest_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nupTest.TextChanged
        Dim x = nupTest.Value
    End Sub

Open in new window

and bindings will be updated as expected
0
 

Author Comment

by:dominicwong
ID: 39798990
Thanks Ark.
Probably because I am using C#, there is no TextChanged handler in NumericUpDown.
Please refer to screenshot.
nup.PNG
0
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 39799001
In VB it hidden from intellisense as well. Just add handler as is in code:
nupTest.TextChanged+=...
0
 

Author Closing Comment

by:dominicwong
ID: 39799014
Thanks Ark for your advice and prompt response. It works!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question