如何设置所选项目在组合框使用C#来匹配我的字符串? [英] How do I set the selected item in a comboBox to match my string using C#?

查看:217
本文介绍了如何设置所选项目在组合框使用C#来匹配我的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串测试1和我的组合框包含测试1 测试2 TEST3 。如何设置所选择的项目为测试1?也就是说,如何将我的字符串匹配到ComboBox项目之一?

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

  comboBox1.SelectedText =测试1;


解决方案

您是否尝试过的文本的财产?这对我的作品。

  ComboBox1.Text =测试1;

该SelectedText属性是组合框的文本框部分可编辑文本的选定部分。

I have a string "test1" and my comboBox contains test1, test2, and test3. How do I set the selected item to "test1"? That is, how do I match my string to one of the comboBox items?

I was thinking of the line below, but this doesn't work.

comboBox1.SelectedText = "test1"; 

解决方案

Have you tried the Text property? It works for me.

ComboBox1.Text = "test1";

The SelectedText property is for the selected portion of the editable text in the textbox part of the combo box.

这篇关于如何设置所选项目在组合框使用C#来匹配我的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆