Solved

NumericUpDown not saving when Commit

Posted on 2014-01-20
7
1,008 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
  • 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 27

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 27

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 27

Accepted Solution

by:
Ark earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PrintingFoundIt(Almost!(Damn!)) 1 26
Printing 1 51
C# winforms programmitically move panels 6 28
Create a WebAPI using a generic return parameter 9 25
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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