Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:31:52+00:00 2026-06-01T19:31:52+00:00

I am making a program which needs to add the value of all numericUpDowns,

  • 0

I am making a program which needs to add the value of all numericUpDowns, and display it on the label.

numericUpDowns are created programatically and added to ArrayList.

ArrayList numericUpDownMy = new ArrayList();
     numericUpDownMy.Add(new NumericUpDown());
        System.Drawing.Point h = new System.Drawing.Point(120, 275+ i * 19);          
        (numericUpDownMy[i] as NumericUpDown).Location = h;
        (numericUpDownMy[i] as NumericUpDown).Size = new System.Drawing.Size(50, 20);
        this.Controls.Add(numericUpDownMy[i] as NumericUpDown);
         int total = (((int)numericUpDown[0]) + ((int)numericUpDown[1]) + ((int)numericUpDown[2]) + ((int)numericUpDown[3]));
    labelScore.Text = total.ToString();

Obviously this doesn’t work as I don’t get the actual value of NumericUpDown. Any advice would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:31:54+00:00Added an answer on June 1, 2026 at 7:31 pm

    change this line :

      decimal total = (numericUpDownMy[1] as NumericUpDown).Value + 
                      (numericUpDownMy[2] as NumericUpDown).Value + 
                      (numericUpDownMy[3] as NumericUpDown).Value;
    

    and besides that don’t use ArrayList, use List<NumericUpDown>, to get rid of all that casting or add to collection at the end. I would wrote that code in this way :

      List<NumericUpDown> numUpDnList = new List<NumericUpDown>();
      for (int i = 0; i < 3; i++)
      {
        NumericUpDown numUpDn = new NumericUpDown();
        numUpDn.Location = new System.Drawing.Point(120, 275 + i * 19);
        numUpDn.Size = new System.Drawing.Size(50, 20);
        this.Controls.Add(numUpDn);
        numUpDnList.Add(numUpDn);
      }
      decimal total = numUpDnList.Sum(updn => updn.Value);
      labelScore.Text = total.ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a program which needs to be listening for UDP Data at all
I'm making a program which create a RAW socket in order to read all
I am making a program in which the user needs to load in multiple
So I'm making a program which is supposed to print a horizontal histogram of
I am making a timetabling program which does one to one matches from SubjectTeacherPeriod
I'm starting a new project which would greatly benefit from program add-ons. The program
I'm making a task-based program that needs to have plugins. Tasks need to have
I'm making a relatively simple program which will also be running on a few
I'm making a back-end function for another area of a program that will add
I'm making a program which controls other processes (as far as stopped and started

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.