我有一个字符串“test1”,我的组合框包含test1、test2和test3。如何设置选中项为“test1”?也就是说,我如何匹配我的字符串到一个组合框项目?

我想的是下面这行,但这不行。

comboBox1.SelectedText = "test1"; 

当前回答

所有设置组合框项的方法、技巧和代码行都将在组合框具有父级之前不起作用。

其他回答

_cmbTemplates.SelectedText = "test1"

或者

_cmbTemplates.SelectedItem= _cmbTemplates.Items.Equals("test1");

你试过文本属性了吗?这对我很管用。

ComboBox1.Text = "test1";

SelectedText属性用于组合框的文本框部分中可编辑文本的选定部分。

comboBox1.SelectedItem.Text = "test1";
ComboBox1.SelectedIndex= ComboBox1.FindString("Matching String");

在windows窗体中尝试此操作。

你可以说comboBox1。[0].ToString();