Clearing NumericUpDown

前端 未结 3 1191
别那么骄傲
别那么骄傲 2021-01-29 12:39

My problem with NumericUpDown control is when the user selects a value from NumericUpDown And unchecks the checkBox1 and clicks the Save button, the value of NumericUpDown not c

相关标签:
3条回答
  • 2021-01-29 12:59

    I was using the NumericUpDown control without the spinners because I wanted only numbers. The control was in a child dialog that was invoked from a listview selection. When the value to be loaded into the NumericUpDown control was zero in the listwiew, a zero was in the control. That zero always had to be cleared out. Here's how I made it "appear" blank. If it was zero, I change the ForeColor of the control to white. I added an Enter event that changed the ForeColor to black and deleted the zero.

    This hid the NumericUpDown control spinners.

    AccessCode.Controls[0].Visible = false;
    

    These statements were in the form initialization. (var code was to be loaded into AccessCode)

            if (code == 0)
            {
                AccessCode.ForeColor = Color.White;
            }
    

    The Enter event code looked like this.

        private void AccessCode_Enter(object sender, EventArgs e)
        {
            if (AccessCode.ForeColor == Color.White)
            {
                AccessCode.ForeColor = Color.Black;
                AccessCode.Focus();
                SendKeys.SendWait("{Delete}");
            }
        }
    

    The AccessCode control also had a Leave event that checked for valid data.

    0 讨论(0)
  • 2021-01-29 13:06

    NumericUpDown does not contain string. It has value as numbers. So it should be:

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
          If CheckBox1.Checked = False Then
                AgeNumericUpDown.Value = 0
          End If
    End Sub
    

    EDIT:

    Check this out then if you don't want the value to be zero, but empty!

     Private Sub BttnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BttnSave.Click
        If AgeNumericUpDown.Value <> 0 Then
            AgeNumericUpDown.Controls(1).Text = ""
        End If
    End Sub
    
    0 讨论(0)
  • 2021-01-29 13:20

    Access the text control of the NumericUpDown and then set text to be blank

    Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
    
        If CheckBox1.Checked = False Then
            AgeNumericUpDown.Controls.Item(1).Text = ""
        End If
    
    End Sub
    

    enter image description here

    0 讨论(0)
提交回复
热议问题