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

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

问题描述

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



我在想下面的行,但这不工作。

  comboBox1.SelectedText =test1; 
解决方案

//msdn.microsoft.com/en-us/library/system.windows.forms.combobox.text.aspxrel =nofollow noreferrer> Text 属性?它适用于我。

  ComboBox1.Text =test1; 

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天全站免登陆