Click here to Skip to main content
15,794,593 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a project that requires several NumericUpDown controls. Some of them change according to the values of others. For example, when nud1 value increases, nud2 value increases as well. But, if nud2 increases, nud1 stays the same. I would add code, but I cannot figure out how to do it at all! Can someone help me?

So, I have 8 NumericUpDown controls on the page. nud1 and nud5 are connected, nud3 and nud6 and nud7 are connected, and nud4 and nud8 are connected. When the first of these NUDs increases or decreases, their counterpart also increases or decreases. However, if the second NUD is increased/decreased, the first one should not change.

I need to know how to separate the UpButton method from the DownButton method. However, I cannot figure out how to utilize it. Help?


What I have tried:

I haven't been able to try anything. Every time I select or type the words "UpButton" or "DownButton", I get red squiggly lines and an error that states "UpButton is not declared. It may be inaccessible due to its protection level." I have tried to invoke it with "nudST.UpButton()"...that's about all I can think to do and it doesn't do anything except give me that little message.
Updated 19-Aug-16 1:33am
Richard MacCutchan 19-Aug-16 5:08am    
You should probably use one of the events that signals when the value changes and modify the connected controls as necessary.
PoiJoy 19-Aug-16 5:11am    
That's just it...WHAT events and WHAT connected controls? I've never used a NumericUpDown control before, but they're very popular, so I want to know HOW to use them...but I can't seem to find anything online about this control that makes sense.
PoiJoy 19-Aug-16 5:34am    
I apparently don't seem to be conveying my problem correctly. I don't know how to read MSDN's "information." I don't know how or where to put whatever code is listed on their site. I'm new to this and reading that site information is like trying to read Greek.
Richard MacCutchan 19-Aug-16 5:38am    
Then you need to go and look for samples and tutorials. See for some useful links.

BTW if you really cannot understand the MSDN documentation you are going to have a lot of problems as a developer.

1 solution

Further to my suggestion above to create a simple application. Create a form with two updown controls and a text box. Make sure the names match those used in the following code sample. Add the method name numericUpDown_ValueChanged to the ValueChanged event of both controls and the code below to your main form code.
private void numericUpDown_ValueChanged(object sender, EventArgs e)
    if (sender == numericUpDown1)
        // if control 1 changes then copy its value to control 2
        numericUpDown2.Value = numericUpDown1.Value;

    // write a message to the textbox showing both values
    StringBuilder sb = new StringBuilder();
    sb.Append("NUD1: ");
    sb.Append(", NUD2: ");
    textBox1.Text = sb.ToString();

Play around with the code and the values as necessary.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900