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

Text プロパティ設定に使用されるサブ項目のインデックスを取得または設定します。
構文
Public Property TextSubItemIndex As Integer
public int TextSubItemIndex {get; set;}

プロパティ値

サブ項目のインデックスを表すInt32値。 既定値は0です。
例外
例外解説
System.ArgumentException値が有効ではありません。
解説
TextFormat プロパティの値がstring.Emptyの場合、Text プロパティは、SelectedItemListItem.SubItemsコレクション内にある、このプロパティのインデックス値によって特定されたSubItemのテキストと一致します。
使用例
データソースにバインドした GcComboBox コントロールを作成するコード例を次に示します。このコントロールでは AutoGenerateColumnstrue の場合、データソースに従って全てのカラムと項目を生成します。データソースに複数のカラムが存在する場合には、 SelectedTextTextSubItemIndex によって、また SelectedValueValueSubItemIndex によって決定されます。この例では他に AutoGenerateColumnsDataSourceDataMember、 TextSubItemIndex と ValueSubItemIndex プロパティを使用しています。
//  Please use the following namespace
//  using System.Windows.Forms;
//  using System.Data;
//  using GrapeCity.Win.Editors;

public void SetDataSourceSettings()
{
    // Creates the GcComboBox control.
    GcComboBox gcComboBox1 = new GcComboBox();

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

    // Sets the AutoGenerateListColumns to true in order to generates columns according
    // the data source.
    gcComboBox1.AutoGenerateColumns = true;
    // Sets the DataSource to a DataSet.
    gcComboBox1.DataSource = dataSet;
    // Sets the DataMember to a table name.
    gcComboBox1.DataMember = "Table";
    // Sets the TextSubItemIndex to 0.
    // The Text property retrieves the value of the first column in the selected row.
    gcComboBox1.TextSubItemIndex = 0;
    // Sets the TextSubItemIndex to 0.
    // The SelectedValue property retrieves the value of the second column in the selected row.
    gcComboBox1.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;
}
'  Please use the following namespace
'  Imports System.Windows.Forms;
'  Imports System.Data;
'  Imports GrapeCity.Win.Editors;

Public Sub SetDataSourceSettings()
    ' Creates the GcComboBox control.
    Dim gcComboBox1 As New GcComboBox()

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

    ' Sets the AutoGenerateListColumns to true in order to generates columns according
    ' the data source.
    gcComboBox1.AutoGenerateColumns = True
    ' Sets the DataSource to a DataSet.
    gcComboBox1.DataSource = dataSet
    ' Sets the DataMember to a table name.
    gcComboBox1.DataMember = "Table"
    ' Sets the TextSubItemIndex to 0.
    ' The Text property retrieves the value of the first column in the selected row.
    gcComboBox1.TextSubItemIndex = 0
    ' Sets the TextSubItemIndex to 0.
    ' The SelectedValue property retrieves the value of the second column in the selected row.
    gcComboBox1.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
参照

GcComboBox クラス
GcComboBox メンバ
SelectedText プロパティ

 

 


© 2004-2015 GrapeCity inc. All rights reserved.