[英]Combobox Focus is not setting
I am trying to set combobox box in constructor. 我正在尝试在构造函数中设置组合框。 But some how it's not set true so, Required field validation is fired and I am not able to change value of combobox.
但是有些方法未设置为true,因此会触发必填字段验证,并且我无法更改combobox的值。 Based on combobox selection Controls is hide and show.
根据组合框选择,控件将被隐藏和显示。 My code is :
我的代码是:
public CompanyAddEdit(MainForm form, int totalItems)
{
passedForm = form;
InitializeComponent();
BindCompanyType();
Id = totalItems;
xmlDocPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Companies.xml");
xDocument = XDocument.Load(xmlDocPath);
cmbbx_companyType.Focus();
}
There are two approaches you can do to have the combobox
focused on the constructor. 您可以通过两种方法使
combobox
专注于构造函数。
Tabindex
property of the combobox
to the lowest. combobox
的Tabindex
属性设置为最低。 cmbbx_companyType.Select()
to set the focus after it is visible. cmbbx_companyType.Select()
来设置焦点。 Here is an updated snippet of your code with Select()
: 这是使用
Select()
更新的代码段:
public CompanyAddEdit(MainForm form, int totalItems)
{
passedForm = form;
InitializeComponent();
BindCompanyType();
Id = totalItems;
xmlDocPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Companies.xml");
xDocument = XDocument.Load(xmlDocPath);
cmbbx_companyType.Select();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.