Solved

NumericUpDown not saving when Commit

Posted on 2014-01-20
7
1,035 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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