ComboBox.DataSource ComboBox.DataSource ComboBox.DataSource ComboBox.DataSource Property


ComboBox의 데이터 소스를 가져오거나 설정합니다.Gets or sets the data source for this ComboBox.

 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

속성 값

IList 인터페이스 또는 Array을(를) 구현하는 개체입니다.An object that implements the IList interface or an Array. 기본값은 null입니다.The default is null.


다음 예제에서는 합니다 DataSource 배열에 요일에 표시할 속성을 ComboBox입니다.The following example uses the DataSource property to display an array of weekdays in a 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.
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", _

        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

    End Sub

End Class


데이터 원본에는 데이터베이스, 웹 서비스 또는 데이터 바인딩된 컨트롤을 생성 하려면 나중에 사용할 수 있는 개체 수 있습니다.A data source can be a database, a Web service, or an object that can later be used to generate data-bound controls. 경우는 DataSource 속성, 항목 컬렉션을 수정할 수 없습니다.When the DataSource property is set, the items collection cannot be modified.

적용 대상