DataGridTableStyle.MappingName DataGridTableStyle.MappingName DataGridTableStyle.MappingName DataGridTableStyle.MappingName Property

정의

이 테이블을 특정 데이터 소스에 매핑하는 데 사용되는 이름을 가져오거나 설정합니다.Gets or sets the name used to map this table to a specific data source.

public:
 property System::String ^ MappingName { System::String ^ get(); void set(System::String ^ value); };
public string MappingName { get; set; }
member this.MappingName : string with get, set
Public Property MappingName As String

속성 값

이 모눈을 특정 데이터 소스에 매핑하는 데 사용되는 이름입니다.The name used to map this grid to a specific data source.

예제

다음 코드 예제에서는 배열을 만듭니다 Widget 개체를 바인딩하는 System.Windows.Forms.DataGrid 배열에는 컨트롤입니다.The following code example creates an array of Widget objects and binds a System.Windows.Forms.DataGrid control to the array. 만든 후는 DataGridTableStyle 설정 및는 MappingName 대괄호 및 클래스의 이름입니다.The code then creates a DataGridTableStyle and sets the MappingName to the name of the class plus brackets.


    void BindToArray()
    {
        // Create an array of Machine objects (defined below).
        array<Machine^>^ Machines = gcnew array<Machine^>(3);
        Machine^ tempMachine;

        tempMachine = gcnew Machine();
        tempMachine->Model = "AAA";
        tempMachine->Id = "A100";
        tempMachine->Price = Convert::ToDecimal(3.80);
        Machines[0] = tempMachine;

        // The first Machine includes an array of Part objects.
        Part^ p1 = gcnew Part();
        p1->PartId = "PartX";
        Part^ p2 = gcnew Part();
        p2->PartId = "PartY";

        // Note that the Machines.Parts property returns an ArrayList.
        // Add the parts to the ArrayList using the AddRange method.
        tempMachine->Parts->AddRange(gcnew array<Part^> {p1, p2}); 

        tempMachine = gcnew Machine();
        tempMachine->Model = "BBB";
        tempMachine->Id = "B100";
        tempMachine->Price = Convert::ToDecimal(1.52);
        Machines[1] = tempMachine;

        tempMachine = gcnew Machine();
        tempMachine->Id = "CCC";
        tempMachine->Model = "B100";
        tempMachine->Price = Convert::ToDecimal(2.14);
        Machines[2] = tempMachine;

        bindedDataGrid->SetDataBinding(Machines, "");
        CreateTableStyle();
    }

    void CreateTableStyle()
    {
        // Creates two DataGridTableStyle objects, one for the Machine
        // array, and one for the Parts ArrayList.

        DataGridTableStyle^ machineTable = gcnew DataGridTableStyle();
        // Sets the MappingName to the class name plus brackets.
        machineTable->MappingName = "Machine[]";

        // Sets the AlternatingBackColor so you can see the difference.
        machineTable->AlternatingBackColor = 
            System::Drawing::Color::LightBlue;

        // Creates three column styles.
        DataGridTextBoxColumn^ modelColumn = gcnew DataGridTextBoxColumn();
        modelColumn->MappingName = "Model";
        modelColumn->HeaderText = "Model";

        DataGridTextBoxColumn^ idColumn = gcnew DataGridTextBoxColumn();
        idColumn->MappingName = "Id";
        idColumn->HeaderText = "Id";

        DataGridTextBoxColumn^ priceColumn = gcnew DataGridTextBoxColumn();
        priceColumn->MappingName = "Price";
        priceColumn->HeaderText = "Price";
        priceColumn->Format = "c";

        // Adds the column styles to the grid table style.
        machineTable->GridColumnStyles->Add(modelColumn);
        machineTable->GridColumnStyles->Add(idColumn);
        machineTable->GridColumnStyles->Add(priceColumn);

        // Add the table style to the collection, but clear the
        // collection first.
        bindedDataGrid->TableStyles->Clear();
        bindedDataGrid->TableStyles->Add(machineTable);

        // Create another table style, one for the related data.
        DataGridTableStyle^ partsTable = gcnew DataGridTableStyle();
        // Set the MappingName to an ArrayList. Note that you need not
        // include brackets.
        partsTable->MappingName = "ArrayList";
        DataGridTextBoxColumn^ partIdColumn = 
            gcnew DataGridTextBoxColumn();
        partIdColumn->MappingName = "PartID";
        partIdColumn->HeaderText = "Part ID";
        partsTable->GridColumnStyles->Add(partIdColumn);
        bindedDataGrid->TableStyles->Add(partsTable);
    }

private:
    ref class Machine
    {
    private:
        String^ machineModel;
        String^ machineID;
        Decimal machinePrice;

        // Use an ArrayList to create a related collection.
        ArrayList^ machineParts;

    public:
        Machine()
        {
            machineParts = gcnew ArrayList; 
        }   

        property String^ Model
        {
            String^ get()
            {
                return machineModel;
            }
            void set(String^ value)
            {
                machineModel = value;
            }
        }

        property String^ Id
        {
            String^ get()
            {
                return machineID;
            }
            void set(String^ value)
            {
                machineID = value;
            }
        }

        property ArrayList^ Parts
        {
            ArrayList^ get()
            {
                return machineParts;
            }
            void set(ArrayList^ value)
            {
                machineParts = value;
            }
        }

        property Decimal Price
        {
            Decimal get()
            {
                return machinePrice;
            }
            void set(Decimal value)
            {
                machinePrice = value;
            }
        }
    };

private:
    ref class Part
    {
    private:
        String^ partId;

    public:
        property String^ PartId
        {
            String^ get()
            {
                return partId;
            }
            void set(String^ value)
            {
                partId = value;
            }
        }
    };

private void BindToArray()
{
    // Create an array of Machine objects (defined below).
    Machine[] Machines = new Machine[3];
    Machine tempMachine;

    tempMachine= new Machine();
    tempMachine.Model = "AAA";
    tempMachine.Id= "A100";
    tempMachine.Price= Convert.ToDecimal(3.80);
    Machines[0]=tempMachine;

    // The first Machine includes an array of Part objects.
    Part p1 = new Part();
    p1.PartId= "PartX";
    Part p2 = new Part();
    p2.PartId= "PartY";

    // Note that the Machines.Parts property returns an ArrayList.
    // Add the parts to the ArrayList using the AddRange method.
    tempMachine.Parts.AddRange (new Part[]{p1, p2});;

    tempMachine= new Machine();
    tempMachine.Model = "BBB";
    tempMachine.Id= "B100";
    tempMachine.Price= Convert.ToDecimal(1.52);
    Machines[1]=tempMachine;

    tempMachine= new Machine();
    tempMachine.Id= "CCC";
    tempMachine.Model = "B100";
    tempMachine.Price= Convert.ToDecimal(2.14);
    Machines[2]=tempMachine;

    dataGrid1.SetDataBinding(Machines, "");
    CreateTableStyle();
}

private void CreateTableStyle()
{
    // Creates two DataGridTableStyle objects, one for the Machine
    // array, and one for the Parts ArrayList.

    DataGridTableStyle MachineTable = new DataGridTableStyle();
    // Sets the MappingName to the class name plus brackets.    
    MachineTable.MappingName= "Machine[]";

    // Sets the AlternatingBackColor so you can see the difference.
    MachineTable.AlternatingBackColor= System.Drawing.Color.LightBlue;

    // Creates three column styles.
    DataGridTextBoxColumn modelColumn = new DataGridTextBoxColumn();
    modelColumn.MappingName= "Model";
    modelColumn.HeaderText= "Model";

    DataGridTextBoxColumn IdColumn = new DataGridTextBoxColumn();
    IdColumn.MappingName= "Id";
    IdColumn.HeaderText= "Id";

    DataGridTextBoxColumn priceColumn = new DataGridTextBoxColumn();
    priceColumn.MappingName= "Price";
    priceColumn.HeaderText= "Price";
    priceColumn.Format = "c";

    // Adds the column styles to the grid table style.
    MachineTable.GridColumnStyles.Add(modelColumn);
    MachineTable.GridColumnStyles.Add(IdColumn);
    MachineTable.GridColumnStyles.Add(priceColumn);

    // Add the table style to the collection, but clear the 
    // collection first.
    dataGrid1.TableStyles.Clear();
    dataGrid1.TableStyles.Add(MachineTable);

    // Create another table style, one for the related data.
    DataGridTableStyle partsTable = new DataGridTableStyle();
    // Set the MappingName to an ArrayList. Note that you need not 
    // include brackets.
    partsTable.MappingName= "ArrayList";
    DataGridTextBoxColumn partIdColumn = new DataGridTextBoxColumn();
    partIdColumn.MappingName= "PartID";
    partIdColumn.HeaderText = "Part ID";
    partsTable.GridColumnStyles.Add(partIdColumn);

    dataGrid1.TableStyles.Add(partsTable);

}
public class Machine
{
    private string model;
    private string id;
    private decimal price;

    // Use an ArrayList to create a related collection.
    private ArrayList parts = new ArrayList();

    public string Model
    {
        get{return model;}
        set{model=value;}
    }
    public string Id
    {
        get{return id;}
        set{id = value;}
    }
    public ArrayList Parts
    {
        get{return parts;}
        set{parts = value;}
    }

    public decimal Price
    {
        get{return price;}
        set{price = value;}
    }
}

public class Part
{
    private string partId;

    public string PartId
    {
        get{return partId;}
        set{partId = value;}
    }
}
Sub BindToArray()
    ' Creates an array of Widget objects (defined below).
    Dim Widgets(2) As Widget
    Dim tempWidget As Widget

    tempWidget = New Widget()
    tempWidget.Model = "AAA"
    tempWidget.Id = "A100"
    tempWidget.Price = Convert.ToDecimal(3.8)
    Widgets(0) = tempWidget

    ' The first Widget includes an array of Part objects.
    Dim p1 As New Part()
    p1.PartId = "PartX"
    Dim p2 As New Part()
    p2.PartId = "PartY"

    ' Note that the Widgets.Parts property returns an ArrayList.
    ' Add the parts to the ArrayList using the AddRange method.
    tempWidget.Parts.AddRange(New Part() {p1, p2})

    tempWidget = New Widget()
    tempWidget.Model = "BBB"
    tempWidget.Id = "B100"
    tempWidget.Price = Convert.ToDecimal(1.52)
    Widgets(1) = tempWidget

    tempWidget = New Widget()
    tempWidget.Id = "CCC"
    tempWidget.Model = "B100"
    tempWidget.Price = Convert.ToDecimal(2.14)
    Widgets(2) = tempWidget

    DataGrid1.SetDataBinding(Widgets, "")
    CreateTableStyle()
End Sub


Private Sub CreateTableStyle()
    ' Creates two DataGridTableStyle objects, one for the Widget
    ' array, and one for the Parts ArrayList.
    Dim widgetTable As New DataGridTableStyle()
    ' Sets the MappingName to the class name plus brackets.    
    widgetTable.MappingName = "Widget[]"

    ' Sets the AlternatingBackColor so you can see the difference.
    widgetTable.AlternatingBackColor = System.Drawing.Color.LightBlue

    ' Creates three column styles.
    Dim modelColumn As New DataGridTextBoxColumn()
    modelColumn.MappingName = "Model"
    modelColumn.HeaderText = "Model"

    Dim IdColumn As New DataGridTextBoxColumn()
    IdColumn.MappingName = "Id"
    IdColumn.HeaderText = "Id"

    Dim priceColumn As New DataGridTextBoxColumn()
    priceColumn.MappingName = "Price"
    priceColumn.HeaderText = "Price"
    priceColumn.Format = "c"

    ' Adds the column styles to the grid table style.
    widgetTable.GridColumnStyles.Add(modelColumn)
    widgetTable.GridColumnStyles.Add(IdColumn)
    widgetTable.GridColumnStyles.Add(priceColumn)

    ' Add the table style to the collection, but clear the 
    ' collection first.
    DataGrid1.TableStyles.Clear()
    DataGrid1.TableStyles.Add(widgetTable)

    ' Create another table style, one for the related data.
    Dim partsTable As New DataGridTableStyle()
    ' Set the MappingName to an ArrayList. Note that you need not 
    ' include brackets.
    partsTable.MappingName = "ArrayList"
    Dim partIdColumn As New DataGridTextBoxColumn()
    partIdColumn.MappingName = "PartID"
    partIdColumn.HeaderText = "Part ID"
    partsTable.GridColumnStyles.Add(partIdColumn)

    DataGrid1.TableStyles.Add(partsTable)
End Sub


Public Class Widget
    Private myModel As String
    Private myId As String
    Private myPrice As Decimal

    ' Use an ArrayList to create a related collection.
    Private myParts As New ArrayList()

    Public Property Model() As String
        Get
            Return myModel
        End Get
        Set(ByVal Value As String)
            myModel = Value
        End Set
    End Property

    Public Property Id() As String
        Get
            Return myId
        End Get
        Set(ByVal Value As String)
            myId = Value
        End Set
    End Property

    Public Property Parts() As ArrayList
        Get
            Return myParts
        End Get
        Set(ByVal Value As ArrayList)
            myParts = Value
        End Set
    End Property

    Public Property Price() As Decimal
        Get
            Return myPrice
        End Get
        Set(ByVal Value As Decimal)
            myPrice = Value
        End Set
    End Property
End Class


Public Class Part
    Private myPartId As String


    Public Property PartId() As String
        Get
            Return myPartId
        End Get
        Set(ByVal Value As String)
            myPartId = Value
        End Set
    End Property
End Class

설명

바인딩하는 DataGrid 개체 유형 개체의 강력한 형식화 된 배열에 public 속성을 포함 해야 합니다.To bind the DataGrid to a strongly typed array of objects, the object type must contain public properties. 만들려면를 DataGridTableStyle 배열을 표시 하는, 설정 합니다 DataGridTableStyle.MappingName 속성을 typename 여기서 typename 개체 유형의 이름으로 바뀝니다.To create a DataGridTableStyle that displays the array, set the DataGridTableStyle.MappingName property to typename where typename is replaced by the name of the object type. 또한는 MappingName 속성이 대/소문자 구분은 형식 이름을 정확 하 게 일치 해야 합니다.Also note that the MappingName property is case-sensitive; the type name must be matched exactly. 참조 된 MappingName 예제에 대 한 속성입니다.See the MappingName property for an example.

바인딩할 수도 있습니다는 DataGridArrayList합니다.You can also bind the DataGrid to an ArrayList. 기능을 ArrayList 여러 형식의 개체를 포함할 수는 있지만 DataGrid 목록의 모든 항목이 첫 번째 항목으로 같은 종류의 경우 이러한 목록에만 바인딩할 수 있습니다.A feature of the ArrayList is that it can contain objects of multiple types, but the DataGrid can only bind to such a list when all items in the list are of the same type as the first item. 즉, 동일한 형식의 모든 개체 여야 하거나 목록에서 첫 번째 항목으로 동일한 클래스에서 상속 해야 합니다.This means that all objects must either be of the same type, or they must inherit from the same class as the first item in the list. 예를 들어 목록의 첫 번째 항목을 Control, 두 번째 항목 수를 TextBox (에서 상속 하는 Control).For example, if the first item in a list is a Control, the second item could be a TextBox (which inherits from Control). 반면에 첫 번째 항목은는 TextBox, 두 번째 개체 일 수 없습니다는 Control합니다.If, on the other hand, the first item is a TextBox, the second object cannot be a Control. 또한는 ArrayList 바인딩될 때에 항목이 있어야 합니다.Further, the ArrayList must have items in it when it is bound. ArrayList 빈 그리드가 발생 합니다.An empty ArrayList will result in an empty grid. 바인딩할 때를 ArrayList설정 합니다 MappingNameDataGridTableStyle "arraylist" (형식 이름).When binding to an ArrayList, set the MappingName of the DataGridTableStyle to "ArrayList" (the type name).

기본값은에서 관리 하는 목록의 이름을 CurrencyManager 이 grid에 대 한 합니다.The default is the name of the list managed by the CurrencyManager for this grid. 합니다 CurrencyManager 에 대 한 합니다 DataGridTableStyle 사용 하도록 설정 됩니다는 DataGridTableStyle 생성자입니다.The CurrencyManager for the DataGridTableStyle is set using the DataGridTableStyle constructor.

합니다 MappingNameChanged 이벤트가 발생할 때를 MappingName 값이 변경 합니다.The MappingNameChanged event occurs when the MappingName value changes.

적용 대상

추가 정보