如何将ComboBox中的项目设置为“SelectedText” ComboBox的属性在Load中动态 [英] How to set an item in ComboBox to "SelectedText" property of ComboBox dynamically in Load

查看:111
本文介绍了如何将ComboBox中的项目设置为“SelectedText” ComboBox的属性在Load中动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WinForm中,我有一个ComboBox。

In WinForm, I have a ComboBox. I am trying to do something like this.

当ComboBox只有一个项目时,该项目应该设置为ComboBox的Selected Text,
它有大于1的项目,第一个项目应设置为选择的文本。

When ComboBox has only 1 item, that item should be set as "Selected Text" for ComboBox, and when it has items more than 1, first item should be set as "Selected Text".

我想这是发生在窗体加载时。

I want this to be happened at the time of Form Load.

我如何做到这一点?

推荐答案

这是很容易的:

comboBox1.SelectedIndex = 0; //This will select the first item in the combobox (zero based numbering)

InitializeComponent();

这篇关于如何将ComboBox中的项目设置为“SelectedText” ComboBox的属性在Load中动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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