PowerTools InputMan for Windows Forms 8.0J
AutoGenerateColumns プロパティ (GcMaskedComboBox)
使用例 

DataSourceプロパティまたはDataMemberプロパティが設定されたときにカラムを自動的に生成するか、しないかを取得または設定します。
構文
Public Property AutoGenerateColumns As Boolean
public bool AutoGenerateColumns {get; set;}

プロパティ値

bool値。カラムを自動的に生成する場合は true、それ以外の場合はfalse
既定値はtrueです。
解説
ソースをDataMemberにバインドすると、データソースに従って、このコントロールのドロップダウンリストに列を自動生成できます。
使用例
データソースにバインドしたGcMaskedComboBoxコントロールを作成するコード例を次に示します。 このコントロールではAutoGenerateColumnstrueの場合、データソースに従って全てのカラムと項目を生成します。データソースに複数のカラムが存在する場合には、SelectedTextTextSubItemIndexによって、またはSelectedValueValueSubItemIndexによって決定されます。この例では他にAutoGenerateColumnsDataSourceDataMemberTextSubItemIndexValueSubItemIndex プロパティを使用しています。
'  Please use the following namespace
'  Imports System.Windows.Forms;
'  Imports System.Data;
'  Imports GrapeCity.Win.Editors;

Public Sub SetDataSourceSettings()
    ' Creates the GcMaskedComboBox control.
    Dim gcMaskedComboBox1 As New GcMaskedComboBox()

    ' Create a new DataSet
    Dim dataSet As DataSet = Me.CreateDataSet()

    ' Sets the AutoGenerateListColumns to true in order to generates columns according
    ' the data source.
    gcMaskedComboBox1.AutoGenerateColumns = True
    ' Sets the DataSource to a DataSet.
    gcMaskedComboBox1.DataSource = dataSet
    ' Sets the DataMember to a table name.
    gcMaskedComboBox1.DataMember = "Table"
    ' Sets the TextSubItemIndex to 0.
    ' The Text property retrieves the value of the first column in the selected row.
    gcMaskedComboBox1.TextSubItemIndex = 0
    ' Sets the TextSubItemIndex to 0.
    ' The SelectedValue property retrieves the value of the second column in the selected row.
    gcMaskedComboBox1.ValueSubItemIndex = 1
End Sub

Private Function CreateDataSet() As DataSet
    ' Create a new DataSet
    Dim dataSet As New DataSet()

    ' Create a new DataTable.
    Dim table As System.Data.DataTable = New DataTable("Table")
    ' Declare variables for DataColumn and DataRow objects.
    Dim column As DataColumn
    Dim row As DataRow
    dataSet.Tables.Add(table)

    ' Create new DataColumn, set DataType, 
    ' ColumnName and add to DataTable.    
    column = New DataColumn()
    column.DataType = System.Type.[GetType]("System.Int32")
    column.ColumnName = "id"
    column.[ReadOnly] = True
    column.Unique = True
    ' Add the Column to the DataColumnCollection.
    table.Columns.Add(column)

    ' Create second column.
    column = New DataColumn()
    column.DataType = System.Type.[GetType]("System.String")
    column.ColumnName = "Item"
    column.AutoIncrement = False
    column.Caption = "Item"
    column.[ReadOnly] = False
    column.Unique = False
    ' Add the column to the table.
    table.Columns.Add(column)

    ' Make the ID column the primary key column.
    Dim PrimaryKeyListColumns As DataColumn() = New DataColumn(0) {}
    PrimaryKeyListColumns(0) = table.Columns("id")
    table.PrimaryKey = PrimaryKeyListColumns

    ' Create three new DataRow objects and add 
    ' them to the DataTable
    Dim i As Integer = 0
    While i <= 2
        row = table.NewRow()
        row("id") = i
        row("Item") = "Item " + i
        table.Rows.Add(row)
        System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
    End While
    Return dataSet
End Function
//  Please use the following namespace
//  using System.Windows.Forms;
//  using System.Data;
//  using GrapeCity.Win.Editors;

public void SetDataSourceSettings()
{
    // Creates the GcMaskedComboBox control.
    GcMaskedComboBox gcMaskedComboBox1 = new GcMaskedComboBox();

    // Create a new DataSet
    DataSet dataSet = this.CreateDataSet();

    // Sets the AutoGenerateListColumns to true in order to generates columns according
    // the data source.
    gcMaskedComboBox1.AutoGenerateColumns = true;
    // Sets the DataSource to a DataSet.
    gcMaskedComboBox1.DataSource = dataSet;
    // Sets the DataMember to a table name.
    gcMaskedComboBox1.DataMember = "Table";
    // Sets the TextSubItemIndex to 0.
    // The Text property retrieves the value of the first column in the selected row.
    gcMaskedComboBox1.TextSubItemIndex = 0;
    // Sets the TextSubItemIndex to 0.
    // The SelectedValue property retrieves the value of the second column in the selected row.
    gcMaskedComboBox1.ValueSubItemIndex = 1;
}

private DataSet CreateDataSet()
{
    // Create a new DataSet.
    DataSet dataSet = new DataSet();

    // Create a new DataTable.
    System.Data.DataTable table = new DataTable("Table");
    // Declare variables for DataColumn and DataRow objects.
    DataColumn column;
    DataRow row;
    dataSet.Tables.Add(table);

    // Create new DataColumn, set DataType, 
    // ColumnName and add to DataTable.    
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.Int32");
    column.ColumnName = "id";
    column.ReadOnly = true;
    column.Unique = true;
    // Add the Column to the DataColumnCollection.
    table.Columns.Add(column);

    // Create second column.
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.String");
    column.ColumnName = "Item";
    column.AutoIncrement = false;
    column.Caption = "Item";
    column.ReadOnly = false;
    column.Unique = false;
    // Add the column to the table.
    table.Columns.Add(column);

    // Make the ID column the primary key column.
    DataColumn[] PrimaryKeyListColumns = new DataColumn[1];
    PrimaryKeyListColumns[0] = table.Columns["id"];
    table.PrimaryKey = PrimaryKeyListColumns;

    // Create three new DataRow objects and add 
    // them to the DataTable.
    for (int i = 0; i <= 2; i++)
    {
        row = table.NewRow();
        row["id"] = i;
        row["Item"] = "Item " + i;
        table.Rows.Add(row);
    }
    return dataSet;
}
参照

GcMaskedComboBox クラス
GcMaskedComboBox メンバ

 

 


© 2004-2015 GrapeCity inc. All rights reserved.