如何验证Windows应用程序中组合的文本框组合框和日期时间选择器
问题描述:
请有人告诉我如何在Windows应用程序中一次验证所有文本框,组合框和日期时间选择器
我已经尝试过使用单个文本框,但是我不知道如何验证单个表单中的所有控件.
我验证一个文本框控件的代码是
Please some one tell me how to validate all text box, combo box and date time pickers at once in windows application
I have tried for single text box, but I don''t know how to validate all controls in a single form.
My code to validate one text box control is
private void txtcmpname_Validating(object sender, CancelEventArgs e)
{
if (((TextBox)sender).Text == "")
{
MessageBox.Show("You must enter a ccomplaintname.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
e.Cancel = true;
}
}
但是,每当我添加另一个文本框或组合框验证时,它都无法正常工作,并且在数据库中插入了一条空白记录.
请向我提供解决方案
But whenever I added another text box or combo box validation then that is not working properly and a blank record is inserted in the database.
Please provide me the solution
答
要真正理解您的问题,我需要知道如何自动更新数据库的代码.为了响应用户的某些行为?
为什么不能使用单个类范围的布尔变量,例如:
私人布尔IsAllControlsVerified = false;
最初将其设置为"false",然后在每次更新数据库后将其重置为"false",然后具有一个功能,用于对要验证的每个控件进行测试,并且,只有在所有控件都经过验证的情况下,才将此标志设置为''真的 ?
当然,仅当此标志为"true"时,才允许继续进行数据库更新.
请扩大对您要做什么的解释.
To really understand your question, I''d need to know how the code that updates the database is called ... automatically ? In response to some user action ?
Why can''t you use a single class-scoped boolean variable, something like:
private bool IsAllControlsVerified = false;
which is set to ''false'' initially, and then reset to ''false after each database update, and then have a function that tests for each control being validated, and, only if all of them are validated, sets this flag to ''true ?
The database update, of course, being allowed to proceed only if this flag if ''true.
Please expand your explanation of what you are trying to do.