我有5个不同的表绑定在Windows窗体上并使用C#。其中一个表是DataGridView。当我使用以下代码加载表单时,我想要聚焦的对象是自动的。
this.termsTableAdapter.Fill(this.terms_DataSet.Terms);
this.customerTableAdapter.Fill(this.customer_Info_DataSet.Customer);
this.customer_ShipTableAdapter.Fill(this.customer_Info_DataSet.Customer_Ship);
this.customer_MailTableAdapter.Fill(this.customer_Info_DataSet.Customer_Mail);
当我添加该行以绑定DataGridView时,我无法将焦点设置为我想设置的控件,即使使用.Focus(),如下所示
this.customer_Ship_ContactsTableAdapter.Fill(this.customer_Info_DataSet.Customer_Ship_Contacts);
customerComboBox.Focus();
为什么datagridview保持焦点而不是我想设置的控件?
我可以点击其他控件来更改焦点,但我希望它设置为form_Load。
答案 0 :(得分:2)
焦点仅在表单可见时才起作用,而在加载事件中,它仍然不可见。
请尝试使用Select()方法:
customerComboBox.Select();