Share via


CheckedListBox.DisplayMember 属性

此属性支持 .NET 基础结构,但不适合在代码中直接使用。

此属性与此类无关。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property DisplayMember As String
用法
Dim instance As CheckedListBox
Dim value As String

value = instance.DisplayMember

instance.DisplayMember = value
public string DisplayMember { get; set; }
public:
property String^ DisplayMember {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_DisplayMember ()

/** @property */
public void set_DisplayMember (String value)
public function get DisplayMember () : String

public function set DisplayMember (value : String)

属性值

一个字符串,指定由 DataSource 指定的对象的属性名称。默认值为空字符串 ("")。

备注

ListControl 类中继承的控件可以显示各种不同类型的对象。如果指定的属性在对象上不存在,或 DisplayMember 属性的值是空字符串 (""),则代之显示的是该对象的 ToString 方法的结果。

如果无法设置 DisplayMember 的新值,则保留以前的值。

此属性与此类无关。

示例

下面的代码示例演示如何通过设置 CheckOnClickSelectionModeThreeDCheckBoxes 属性来初始化 CheckedListBox 控件。示例使用控件来填充 CheckedListBox,并将 DisplayMember 设置为控件的 Control.Name 属性。

若要运行该示例,请将下面的代码粘贴到包含名为 CheckedListBox1CheckedListBox 的窗体中,并从该窗体的构造函数或 Load 方法中调用 InitializeCheckListBox 方法。

// This method initializes CheckedListBox1 with a list of all 
// the controls on the form. It sets the selection mode
// to single selection and allows selection with a single click.
// It adds itself to the list before adding itself to the form.

internal System.Windows.Forms.CheckedListBox CheckedListBox1;

private void InitializeCheckedListBox()
{
    this.CheckedListBox1 = new CheckedListBox();
    this.CheckedListBox1.Location = new System.Drawing.Point(40, 90);
    this.CheckedListBox1.CheckOnClick = true;
    this.CheckedListBox1.Name = "CheckedListBox1";
    this.CheckedListBox1.Size = new System.Drawing.Size(120, 94);
    this.CheckedListBox1.TabIndex = 1;
    this.CheckedListBox1.SelectionMode = SelectionMode.One;
    this.CheckedListBox1.ThreeDCheckBoxes = true;

    foreach ( Control aControl in this.Controls )
    {
        this.CheckedListBox1.Items.Add(aControl, false);
    }

    this.CheckedListBox1.DisplayMember = "Name";
    this.CheckedListBox1.Items.Add(CheckedListBox1);
    this.Controls.Add(this.CheckedListBox1);
}
   // This method initializes CheckedListBox1 with a list of all 
   // the controls on the form. It sets the selection mode
   // to single selection and allows selection with a single click.
   // It adds itself to the list before adding itself to the form.
internal:
   System::Windows::Forms::CheckedListBox^ CheckedListBox1;

private:
   void InitializeCheckedListBox()
   {
      this->CheckedListBox1 = gcnew CheckedListBox;
      this->CheckedListBox1->Location = System::Drawing::Point( 40, 90 );
      this->CheckedListBox1->CheckOnClick = true;
      this->CheckedListBox1->Name = "CheckedListBox1";
      this->CheckedListBox1->Size = System::Drawing::Size( 120, 94 );
      this->CheckedListBox1->TabIndex = 1;
      this->CheckedListBox1->SelectionMode = SelectionMode::One;
      this->CheckedListBox1->ThreeDCheckBoxes = true;
      System::Collections::IEnumerator^ myEnum = this->Controls->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Control^ aControl = safe_cast<Control^>(myEnum->Current);
         this->CheckedListBox1->Items->Add( aControl, false );
      }

      this->CheckedListBox1->DisplayMember = "Name";
      this->CheckedListBox1->Items->Add( CheckedListBox1 );
      this->Controls->Add( this->CheckedListBox1 );
   }

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

CheckedListBox 类
CheckedListBox 成员
System.Windows.Forms 命名空间