作成日:2025/05/01 最終更新日: 2025/05/01
文書種別
使用方法
詳細
GcComboBoxCell型セルがアクティブになっている場合に、ドロップダウンリストの指定したインデックス番号の項目を選択して、セルの値として設定できます。
以下にサンプルコードを紹介します。
サンプルコードでは、ボタンクリック時に現在アクティブのGcComboBoxCellType セルにインデックス(index=1)を指定し、対象の値を表示しています。
◎サンプルコード(VB)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' GcComboBoxCellType型セル用データの作成
Dim dt As New DataTable()
With dt
.Columns.AddRange({New DataColumn("Code", GetType(Int32)), New DataColumn("Name")})
.Rows.Add(100, "A")
.Rows.Add(200, "B")
.Rows.Add(300, "C")
.AcceptChanges()
End With
' GcComboBoxCellType型セルの作成
Dim comboCell As New GcComboBoxCellType()
With comboCell
.DataSource = dt
.DropDownStyle = ComboBoxStyle.DropDownList
.EditorValue = GcComboBoxEditorValue.Value
.TextSubItemIndex = 1
.ValueSubItemIndex = 0
End With
' シートの設定
FpSpread1.ActiveSheet.Columns(0).CellType = comboCell
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim rowIndex As Integer = FpSpread1.ActiveSheet.ActiveRowIndex
Dim colIndex As Integer = FpSpread1.ActiveSheet.ActiveColumnIndex
If TypeOf FpSpread1.ActiveSheet.ActiveCell.CellType Is GcComboBoxCellType Then
Dim combo As GcComboBoxCellType = TryCast(FpSpread1.ActiveSheet.GetCellType(rowIndex, colIndex), GcComboBoxCellType)
Dim index As Integer = 1 ' <== インデックス番号の指定
Dim value As Object = (TryCast(combo.Items(index),ListItemInfo)).SubItems(combo.ValueSubItemIndex).Value
FpSpread1.ActiveSheet.SetValue(rowIndex, colIndex, value)
End If
End Sub
◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
// GcComboBoxCellType型セル用データの作成
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("Code", typeof(int)),
new DataColumn("Name")
});
dt.Rows.Add(100, "A");
dt.Rows.Add(200, "B");
dt.Rows.Add(300, "C");
dt.AcceptChanges();
// GcComboBoxCellType型セルの作成
GcComboBoxCellType comboCell = new GcComboBoxCellType
{
DataSource = dt,
DropDownStyle = ComboBoxStyle.DropDownList,
EditorValue = GcComboBoxEditorValue.Value,
TextSubItemIndex = 1,
ValueSubItemIndex = 0
};
// シートの設定
fpSpread1.ActiveSheet.Columns[0].CellType = comboCell;
}
private void button1_Click(object sender, EventArgs e)
{
int rowIndex = fpSpread1.ActiveSheet.ActiveRowIndex;
int colIndex = fpSpread1.ActiveSheet.ActiveColumnIndex;
if (fpSpread1.ActiveSheet.ActiveCell.CellType is GcComboBoxCellType)
{
GcComboBoxCellType combo = fpSpread1.ActiveSheet.GetCellType(rowIndex, colIndex) as GcComboBoxCellType;
int index = 1; // <== インデックス番号の指定
object value = (combo.Items[index] as ListItemInfo).SubItems[combo.ValueSubItemIndex].Value;
fpSpread1.ActiveSheet.SetValue(rowIndex, colIndex, value);
}
}
<実行イメージ>