CheckedListBox.DisplayMember Proprietà

Definizione

Ottiene o imposta una stringa che specifica una proprietà degli oggetti presenti nella casella di riepilogo di cui si desidera visualizzare il contenuto.

public:
 property System::String ^ DisplayMember { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Browsable(false)]
public string DisplayMember { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.DisplayMember : string with get, set
Public Property DisplayMember As String

Valore della proprietà

String

Stringa che specifica il nome di una proprietà degli oggetti contenuti nella casella di riepilogo. Il valore predefinito è una stringa vuota ("").

Attributi

Esempio

Nell'esempio di codice seguente viene illustrata l'inizializzazione di un CheckedListBox controllo impostando le CheckOnClickproprietà , SelectionModee ThreeDCheckBoxes . L'esempio popola con CheckedListBox i controlli e imposta l'oggetto sulla DisplayMember Control.Name proprietà del controllo .

Per eseguire l'esempio, incollare il codice seguente in un modulo contenente un CheckedListBox oggetto denominato CheckedListBox1 e chiamare il InitializeCheckListBox metodo dal costruttore del modulo o dal metodo Load.

   // 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 );
   }
// 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.
Friend WithEvents CheckedListBox1 As System.Windows.Forms.CheckedListBox

Private Sub InitializeCheckedListBox()
    Me.CheckedListBox1 = New CheckedListBox
    Me.CheckedListBox1.Location = New System.Drawing.Point(40, 90)
    Me.CheckedListBox1.CheckOnClick = True
    Me.CheckedListBox1.Name = "CheckedListBox1"
    Me.CheckedListBox1.Size = New System.Drawing.Size(120, 94)
    Me.CheckedListBox1.TabIndex = 1
    Me.CheckedListBox1.SelectionMode = SelectionMode.One
    Me.CheckedListBox1.ThreeDCheckBoxes = True

    Dim aControl As Control
    For Each aControl In Me.Controls
        Me.CheckedListBox1.Items.Add(aControl, False)
    Next

    Me.CheckedListBox1.DisplayMember = "Name"
    Me.CheckedListBox1.Items.Add(CheckedListBox1)
    Me.Controls.Add(Me.CheckedListBox1)
End Sub

Commenti

Per impostazione predefinita, CheckedListBox visualizza la stringa predefinita per gli elementi contenuti. Tuttavia, CheckedListBox può visualizzare diversi tipi di oggetti e può essere necessario modificare la stringa visualizzata specificando la DisplayMember proprietà . Se la proprietà specificata non esiste o il valore della DisplayMember proprietà è una stringa vuota (""), vengono visualizzati i risultati del metodo dell'oggetto ToString .

Se non è possibile impostare il nuovo valore di DisplayMember , viene mantenuto il valore precedente.

Si applica a