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

问题描述

在 WinForm 中,我有一个 ComboBox.我正在尝试做这样的事情.

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

当 ComboBox 只有 1 个项目时,该项目应设置为 ComboBox 的选定文本",并且当它有超过 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".

我希望这在 Form Load 时发生.

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

我该怎么做?

推荐答案

如果我理解正确的话,您希望组合框的第一项被选择/显示在组合框中.

If I understand it the right way, you want the first item of the combobox to be selected/shown in comboBox.

这很简单:

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

要在表单显示后立即设置,只需将其放在

To set it right after the form is shown simply put it after

InitializeComponent();

适当的形式.

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

10-31 09:32