Raghavendra
Raghavendra

Reputation: 31

C# numericupdown control - focus

I am using numericupdown controls, one for setting the minimum range and other for the maximum range. User removes the entire value present in the minimum range numeric updown by pressing delete key or backspace key and moves to the maximumrange, now in the minimum range numericupdown a default value to be displayed. For this I am listening to the LostFocus events and assigning the values , but the values are not displayed. How to display the values in this case.

Upvotes: 1

Views: 2766

Answers (2)

nonamelive
nonamelive

Reputation: 6510

        private void numericUpDown1_Leave(object sender, EventArgs e)
        {
            if (numericUpDown1.Controls[1].Text == String.Empty)
            {
                numericUpDown1.Controls[1].Text = numericUpDown1.Minimum.ToString();
                numericUpDown1.Value = numericUpDown1.Minimum;
            }
        }

Upvotes: 1

Webleeuw
Webleeuw

Reputation: 7272

Does this answer your question?

if (numericUpDown1.Text == String.Empty) {
    numericUpDown1.Text = numericUpDown1.Minimum.ToString();
    numericUpDown1.Value = numericUpDown1.Minimum;
}

Upvotes: 0

Related Questions