ComboBox.SelectedIndex 属性 (System.Windows.Forms) 您所在的位置:网站首页 combox控件获取选中文本的值 ComboBox.SelectedIndex 属性 (System.Windows.Forms)

ComboBox.SelectedIndex 属性 (System.Windows.Forms)

2023-08-16 17:44| 来源: 网络整理| 查看: 265

ComboBox.SelectedIndex 属性 参考 定义 命名空间: System.Windows.Forms 程序集:System.Windows.Forms.dll

重要

一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。

获取或设置指定当前选定项的索引。

public: virtual property int SelectedIndex { int get(); void set(int value); }; [System.ComponentModel.Browsable(false)] public override int SelectedIndex { get; set; } [] member this.SelectedIndex : int with get, set Public Overrides Property SelectedIndex As Integer 属性值 Int32

当前选定项的从零开始的索引。 如果未选定任何项,则返回值为负一 (-1)。

属性 BrowsableAttribute 例外 ArgumentOutOfRangeException

指定的索引小于或等于 -2。

- 或 -

指定的索引大于或等于组合框中的项数。

示例

下面的代码示例演示如何使用 FindString 方法和 SelectedIndex 属性。 该示例是类概述中完整示例的 ComboBox 一部分。

void findButton_Click( Object^ sender, System::EventArgs^ e ) { int index = comboBox1->FindString( textBox2->Text ); comboBox1->SelectedIndex = index; } private void findButton_Click(object sender, System.EventArgs e) { int index = comboBox1.FindString(textBox2.Text); comboBox1.SelectedIndex = index; } Private Sub findButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim index As Integer index = comboBox1.FindString(textBox2.Text) comboBox1.SelectedIndex = index End Sub 注解

此属性指示组合框列表中当前所选项的从零开始的索引。 设置新索引会 SelectedIndexChanged 引发 事件。

SelectedIndex、 SelectedValue和 FormattingEnabled 是相关的,如下所示:

如果 FormattingEnabled 为 false, SelectedIndex 则当 为空时 SelectedValue ,不会设置为 -1。

如果 FormattingEnabled 为 true, SelectedIndex 则当 为空时 SelectedValue ,将设置为 -1。

注意

若要取消选择当前所选项,请将 SelectedIndex 设置为 -1。 如果项是数据绑定项,则不能 SelectedIndex 将项的 ComboBox 设置为 -1。

适用于 另请参阅 Position FormattingEnabled SelectedValue


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有