ComboBox.DataSource Eigenschaft

Definition

Ruft die Datenquelle für diese ComboBox ab oder legt diese fest.

public:
 property System::Object ^ DataSource { System::Object ^ get(); void set(System::Object ^ value); };
public object DataSource { get; set; }
member this.DataSource : obj with get, set
Public Property DataSource As Object

Eigenschaftswert

Object

Ein Objekt, das die IList-Schnittstelle oder ein Array implementiert. Der Standardwert ist null.

Beispiele

Im folgenden Beispiel wird die DataSource Eigenschaft verwendet, um ein Array von Wochentagen in einer ComboBox.

using System.Windows.Forms;

namespace ComboBox_DataSource_Sample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            // Initialize an array with data to bind to the combo box.
            var daysOfWeek =
                new[] { "Monday", "Tuesday", "Wednesday", 
                        "Thursday", "Friday", "Saturday", 
                        "Sunday" };

            // Initialize combo box
            var comboBox = new ComboBox
                                {
                                    DataSource = daysOfWeek,
                                    Location = new System.Drawing.Point(12, 12),
                                    Name = "comboBox",
                                    Size = new System.Drawing.Size(166, 21),
                                    DropDownStyle = ComboBoxStyle.DropDownList
                                };

            // Add the combo box to the form.
            this.Controls.Add(comboBox);
        }
    }
}
Imports System.Windows.Forms

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load

        Dim comboBox As New ComboBox
        Dim daysOfWeek As String() = _
            New String() {"Monday", "Tuesday", "Wednesday", _
                          "Thursday", "Friday", "Saturday", _
                          "Sunday"}

        With comboBox
            .DataSource = daysOfWeek
            .Location = New System.Drawing.Point(12, 12)
            .Name = "comboBox"
            .Size = New System.Drawing.Size(166, 21)
            .DropDownStyle = ComboBoxStyle.DropDownList
        End With

        Me.Controls.Add(comboBox)
    End Sub

End Class

Hinweise

Eine Datenquelle kann eine Datenbank, ein Webdienst oder ein Objekt sein, das später zum Generieren von datengebundenen Steuerelementen verwendet werden kann. Wenn die DataSource Eigenschaft festgelegt wird, kann die Elementauflistung nicht geändert werden.

Gilt für