日期和时间选择器-压光机 [英] Date and time picker- close calender

查看:96
本文介绍了日期和时间选择器-压光机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是项目代码和C#的新手.我希望您提出以下建议:

当前问题 :(:我有一个文本框,其中输入了参考号,这个数字的验证发生在textbox_leave事件中.问题是用户何时到达日期和时间选择器,如果文本框不是有效的消息框,而日期和时间选择器仍保持下拉状态.

理想解决方案 :):如果文本框无效,则日期和时间选择器日历不会下降,而是将焦点放在文本框上.

谢谢

Hi guys,

I''m new to project code and C#. I would appeciate advice on the following:

Current problem :(: I have a textbox in which a ref no. is input, the validation of this number occurs in a textbox_leave event. Problem is when user then goes to date and time picker, and if textbox isnt valid a messagebox comes up, and date and time picker just remains dropped down.

Ideal solution:): if textbox invalid, the date and time picker calender doesnt drop down and focus to be on back on textbox.

Thank you

推荐答案

private void textBox2_Leave(object sender, EventArgs e)
       {
           var carindex2 = (textBox2.Text.Trim()).ToUpper();

               string connectionString = "Provider= OraOLEDB.Oracle; Data Source=TSTEEL;User ID=NEW_DBA;Password=tsteel";
           string sql = "SELECT count(car_index) FROM CAR where car_index = '" + carindex2 + "'";
           OleDbConnection connection = new OleDbConnection(connectionString);
           OleDbCommand command = new OleDbCommand(sql, connection);
           connection.Open();
           int count = Convert.ToInt32(command.ExecuteScalar());
           connection.Close();

           if (count == 0)
           { ////error message if car index doesnt exist

               MessageBox.Show("Car Index does not exist, Please try again!", "Car not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
               textBox2.Clear();



           }

       }


如果文本框无效,则将焦点再次设置为文本框,如以下代码所示

If textbox is invalid then set focus to textbox again like following code

textbox1.Focus();



希望这对您有帮助...



Hope this will help you...


尝试此代码
try this code
private void textBox2_Leave(object sender, EventArgs e)
        {
            var carindex2 = (textBox2.Text.Trim()).ToUpper();
 
                string connectionString = "Provider= OraOLEDB.Oracle; Data Source=TSTEEL;User ID=NEW_DBA;Password=tsteel";
            string sql = "SELECT count(car_index) FROM CAR where car_index = '" + carindex2 + "'";
            OleDbConnection connection = new OleDbConnection(connectionString);
            OleDbCommand command = new OleDbCommand(sql, connection);
            connection.Open();
            int count = Convert.ToInt32(command.ExecuteScalar());
            connection.Close();
 
            if (count == 0)
            { ////error message if car index doesnt exist
              
                MessageBox.Show("Car Index does not exist, Please try again!", "Car not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBox2.Focus();
                textBox2.Clear();
            }
 
        }


这篇关于日期和时间选择器-压光机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆