Solved

NumericUpDown not saving when Commit

Posted on 2014-01-20
7
967 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 27

Expert Comment

by:Ark
Comment Utility
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
Comment Utility
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
Comment Utility
In VB it hidden from intellisense as well. Just add handler as is in code:
nupTest.TextChanged+=...
0
 

Author Closing Comment

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now