Solved

NumericUpDown not saving when Commit

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

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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