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

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

问题描述

我有一个字符串test1",我的组合框包含 test1test2test3.如何将所选项目设置为test1"?也就是说,如何将我的字符串与组合框项目之一匹配?

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"; 

推荐答案

这应该可以解决问题:

Combox1.SelectedIndex = Combox1.FindStringExact("test1")

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

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