简体   繁体   中英

How depending the selected value of a combobox, i can allow in a numericupdown the value to be >= 0?

示例我有一个包含 3 列表的组合框:输入、退出和传输以及一个名为:txtTotal 的数字向上,当我选择输入或退出时从 0 开始应该显示错误丢失总数但是如果选择传输应该允许您继续,即使它是0 或其他数字

If you want to show error missing total when you select entry or exit and allow you to continue even if txttotal shows 0 or another number when you select transfer, you could refer to the following code:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        comboBox1.Items.Add("Entry");
        comboBox1.Items.Add("Exit");
        comboBox1.Items.Add("Transfer");
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboBox1.Text == "Entry" || comboBox1.Text == "Exit")
        {
            MessageBox.Show("Error missing total is " + txtTotal.Text);
        }
        if (comboBox1.Text == "Transfer") 
        {
            // You should replace this code with what you want to do
            string FileToRead = "the path of txt file";
            string[] lines = File.ReadAllLines(FileToRead);
            foreach (string str in lines)
            {
                if (str == "2")
                {
                    txtTotal.UpButton();
                }
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM