提问人:UHM 提问时间:10/24/2023 更新时间:10/25/2023 访问量:45
设置在离开 ComboBox 时将焦点放在下一个项目变得可见
Setting Focus on next item becoming visible while leaving ComboBox
问:
我有一个 with 设置为 .按顺序排列的下一个控件是 .取决于所选的 is 或 not .此外,不应输入另一个文本,该文本不包含在 .因此,在离开 I 时检查 的值。ComboBox
AutoCompleteMode
Suggest
TextBox
ComboBox
TextBox
visible
visible
ComboBox
ComboBox
Validating
private void cb_Validating(object sender, CancelEventArgs e)
{
if(cb.SelectedValue == null)
{
e.Cancel = true;
}
tb.Visible = cb.Text.Contains("XX"); // makes TextBox visible/invisible
}
现在有一个问题,如果是不可见的,并且用户输入一些字母,然后用键向下转到一个使可见的项目,然后按制表键,则焦点会跳过以下可见的文本框。在这种情况下,如何确保文本框不会被跳过?TextBox
ComboBox
TextBox
答:
1赞
dr.null
10/25/2023
#1
实现 Validated 事件以显示并选择是否满足条件。否则,请将其隐藏并调用 SelectNextControl
方法以选择 Tab 键顺序中的下一个控件。TextBox
private void cb_Validating(object sender, CancelEventArgs e)
{
e.Cancel = cb.SelectedItem == null;
}
private void cb_Validated(object sender, EventArgs e)
{
tb.Visible = cb.Text.Contains("some text");
if (tb.Visible) tb.Select();
else SelectNextControl(cb, true, true, true, true);
}
0赞
jdweng
10/25/2023
#2
请尝试以下操作:
private void cb_Validating(object sender, CancelEventArgs e)
{
ComboBox cb = sender as ComboBox;
if (cb.SelectedValue == null)
{
e.Cancel = true;
}
tb.Visible = cb.Text.Contains("XX"); // makes TextBox visible/invisible
int index = cb.SelectedIndex;
cb.SelectedIndex = index + 1;
}
评论