作成日: 2022/01/21 最終更新日: 2022/02/24
文書種別
使用方法
詳細
コンボボックス型セルで項目を選択した場合には、FpSpreadクラスのComboSelChangeイベントが発生します。
ComboSelChangeイベントに下記のようなコードを記述することで、別の列のコンボボックス型セルの項目を選択することができます。
◎サンプルコード(VB)
◎サンプルコード(C#)
ComboSelChangeイベントに下記のようなコードを記述することで、別の列のコンボボックス型セルの項目を選択することができます。
◎サンプルコード(VB)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' コンボボックス型セルの設定
Dim comboCell1 As New FarPoint.Win.Spread.CellType.ComboBoxCellType()
comboCell1.Items = New String() {"A", "B", "C"}
comboCell1.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.Index
FpSpread1.ActiveSheet.Columns(0).CellType = comboCell1
' コンボボックス型セルの設定
Dim comboCell2 As New FarPoint.Win.Spread.CellType.ComboBoxCellType()
comboCell2.Items = New String() {"100", "200", "300"}
comboCell2.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.Index
FpSpread1.ActiveSheet.Columns(1).CellType = comboCell2
End Sub
Private Sub FpSpread1_ComboSelChange(sender As Object, e As EditorNotifyEventArgs) Handles FpSpread1.ComboSelChange
' 第1列のコンボボックス型セルで選択した項目のインデックス番号を第2列のコンボボックス型セルのValueプロパティに設定
If e.Column = 0 Then
e.View.GetSheetView().SetValue(e.Row, 1, DirectCast(e.EditingControl, FarPoint.Win.FpCombo).SelectedIndex)
End If
End Sub
' コンボボックス型セルの設定
Dim comboCell1 As New FarPoint.Win.Spread.CellType.ComboBoxCellType()
comboCell1.Items = New String() {"A", "B", "C"}
comboCell1.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.Index
FpSpread1.ActiveSheet.Columns(0).CellType = comboCell1
' コンボボックス型セルの設定
Dim comboCell2 As New FarPoint.Win.Spread.CellType.ComboBoxCellType()
comboCell2.Items = New String() {"100", "200", "300"}
comboCell2.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.Index
FpSpread1.ActiveSheet.Columns(1).CellType = comboCell2
End Sub
Private Sub FpSpread1_ComboSelChange(sender As Object, e As EditorNotifyEventArgs) Handles FpSpread1.ComboSelChange
' 第1列のコンボボックス型セルで選択した項目のインデックス番号を第2列のコンボボックス型セルのValueプロパティに設定
If e.Column = 0 Then
e.View.GetSheetView().SetValue(e.Row, 1, DirectCast(e.EditingControl, FarPoint.Win.FpCombo).SelectedIndex)
End If
End Sub
◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
// コンボボックス型セルの設定
FarPoint.Win.Spread.CellType.ComboBoxCellType comboCell1 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
comboCell1.Items = (new String[] { "A", "B", "C" });
comboCell1.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.Index;
fpSpread1.ActiveSheet.Columns[0].CellType = comboCell1;
// コンボボックス型セルの設定
FarPoint.Win.Spread.CellType.ComboBoxCellType comboCell2 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
comboCell2.Items = (new String[] { "100", "200", "300" });
comboCell2.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.Index;
fpSpread1.ActiveSheet.Columns[1].CellType = comboCell2;
}
private void fpSpread1_ComboSelChange(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
{
// 第1列のコンボボックス型セルで選択した項目のインデックス番号を第2列のコンボボックス型セルのValueプロパティに設定
if(e.Column == 0)
{
FarPoint.Win.FpCombo comboCell = e.EditingControl as FarPoint.Win.FpCombo;
e.View.GetSheetView().SetValue(e.Row, 1, comboCell.SelectedIndex);
}
}
{
// コンボボックス型セルの設定
FarPoint.Win.Spread.CellType.ComboBoxCellType comboCell1 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
comboCell1.Items = (new String[] { "A", "B", "C" });
comboCell1.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.Index;
fpSpread1.ActiveSheet.Columns[0].CellType = comboCell1;
// コンボボックス型セルの設定
FarPoint.Win.Spread.CellType.ComboBoxCellType comboCell2 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
comboCell2.Items = (new String[] { "100", "200", "300" });
comboCell2.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.Index;
fpSpread1.ActiveSheet.Columns[1].CellType = comboCell2;
}
private void fpSpread1_ComboSelChange(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
{
// 第1列のコンボボックス型セルで選択した項目のインデックス番号を第2列のコンボボックス型セルのValueプロパティに設定
if(e.Column == 0)
{
FarPoint.Win.FpCombo comboCell = e.EditingControl as FarPoint.Win.FpCombo;
e.View.GetSheetView().SetValue(e.Row, 1, comboCell.SelectedIndex);
}
}