Reputation: 3
How to get the values from dynamic NumericUpDown
in C#?
Here is my code,
for (int i=0; i<n;i++)
{
NumericUpDown notele = new NumericUpDown();
notele.Name = "note" + i.ToString();
notele.Location = new System.Drawing.Point(280, 208 + (30 * i));
notele.Size = new System.Drawing.Size(40, 25);
notele.BackColor = System.Drawing.SystemColors.ControlDark;
notele.Maximum = new decimal(new int[] {10,0,0, 0});
this.Controls.Add(notele);
}
Upvotes: 0
Views: 894
Reputation: 5225
You can still utilise the ValueChanged event:
...
notelle.ValueChanged += UpDnValueChangedHandler;
this.Controls.Add(notele);
}
private void UpDnValueChangedHandler(object sender, EventArgs e)
{
// sender references the control which value was changed:
NumericUpDown notelle = sender as NumericUpDown;
// further processing goes here
}
Upvotes: 0
Reputation: 101681
Access your controls using the Control collection of your form and pass to it the name of your numericUpDown
control:
var numericUpDown = this.Controls["note0"] as NumericUpDown;
if(numericUpDown != null)
{
var value = numericUpDown.Value;
}
Upvotes: 2