如果没有输入任何内容,我正在验证文本框中的数据
public bool IsPresent(TextBox textBox, string name)
{
if (textBox.Text == "")
{
MessageBox.Show(name + " is a required field.", "Entry Error");
textBox.Focus();
return false;
}
return true;
}
但是,我想将name参数作为文本框绑定到的数据集datacolumn中的实际名称传递。
public bool isValidData(List<TextBox> textBoxList)
{
foreach (TextBox textBox in textBoxList)
{
//string name = techSupportDataSet.Technicians.NameColumn.ColumnName;
IsPresent(textBox, name);
}
return false;
}
您可以看到注释掉的代码显式获取特定的数据列名称,但我希望它是一个变量,具体取决于绑定的文本框。
我已经尝试查找MSDN文档,但我似乎无法找到任何接受绑定控件作为参数的方法。任何正确方向的点都会非常感激!
答案 0 :(得分:0)
在消息框中显示字段名称不是一个好主意。例如,如果DBA为用户的名字创建了一个字段FName
,那么该消息将显示为FName is a required field.
这将使操作员感到困惑。您可以在该控件的AccessibleName
或AccessibleDescription
属性中指定显示名称,然后您可以在代码中使用它。
//Assign display name in AccessibleName property
textBox.AccessibleName= "User's First Name"
//use that field
IsPresent(textBox, textBox.AccessibleName);