【问题标题】:Setting dropdown list selected value in Visual C# 2010在 Visual C# 2010 中设置下拉列表选定值
【发布时间】:2015-05-18 06:53:32
【问题描述】:

我在 Visual Studio 2010 中有一个 Windows 窗体项目,我想知道如何设置下拉菜单的默认选定值。

例如,当我当前运行项目时,下拉菜单是空白的,直到我单击它并选择一个值。我想修改下拉菜单,使其默认具有用户可以更改的值。如何在设计器视图和运行时通过 C# 完成此操作?

【问题讨论】:

  • 您使用的是哪个 UI 框架(Winforms、WPF 等)?或者,由于您似乎认为您的问题与 Visual Studio 直接相关,是否有您希望默认的特定 Visual Studio 下拉菜单?

标签: c# winforms visual-studio-2010 drop-down-menu


【解决方案1】:

设置属性 SelectedIndex。

运行时:

comboBox1.SelectedIndex = 0; //Selects the first option

如果要选择包含特定文本的选项。

int index = comboBox1.FindString("burger"); //get index
comboBox1.SelectedIndex = index;

设计时:

选择控件,进入属性窗口,寻找 SelectedIndex 属性,设置所需的索引。

【讨论】:

    最近更新 更多