作成日: 2015/08/26 最終更新日: 2015/08/26
文書種別
使用方法
詳細
1列目と2列目にコンボボックスを設定し、1列目のコンボボックスで選択した項目によって2列目で選択できる項目を変更するには、BeforeEditイベントで1列目の選択項目を判定し、StyleのComboListプロパティを設定する処理を実装します。
◎サンプルコード(Visual Basic)
◎サンプルコード(C#)
◎サンプルコード(Visual Basic)
Private ReadOnly list_a As String = "a|b|c"
Private ReadOnly list_b1 As String = " "
Private ReadOnly list_b2 As String = "1|3|5"
Private ReadOnly list_b3 As String = "2|4|6|8"
Private ReadOnly list_b4 As String = "7|9"
Private Sub Form1_Load(sender As Object, e As EventArgs)
C1FlexGrid1.Styles.Add("Combo1")
C1FlexGrid1.Styles("Combo1").ComboList = list_a
C1FlexGrid1.Styles.Add("Combo2")
C1FlexGrid1.Styles("Combo2").ComboList = list_b1
C1FlexGrid1.Cols(1).Style = C1FlexGrid1.Styles("Combo1")
C1FlexGrid1.Cols(2).Style = C1FlexGrid1.Styles("Combo2")
End Sub
Private Sub C1FlexGrid1_BeforeEdit(sender As Object, e As C1.Win.C1FlexGrid.RowColEventArgs)
If e.Col = 2 Then
If IsNothing(C1FlexGrid1(e.Row, 1)) Then
C1FlexGrid1.Cols(2).Style.ComboList = list_b1
ElseIf C1FlexGrid1(e.Row, 1).ToString() = "a" Then
C1FlexGrid1.Cols(2).Style.ComboList = list_b2
ElseIf C1FlexGrid1(e.Row, 1).ToString() = "b" Then
C1FlexGrid1.Cols(2).Style.ComboList = list_b3
ElseIf C1FlexGrid1(e.Row, 1).ToString() = "c" Then
C1FlexGrid1.Cols(2).Style.ComboList = list_b4
End If
End If
End Sub
Private Sub C1FlexGrid1_CellChanged(sender As Object, e As C1.Win.C1FlexGrid.RowColEventArgs)
If e.Col = 1 Then
C1FlexGrid1(e.Row, 2) = Nothing
End If
End Sub
Private ReadOnly list_b1 As String = " "
Private ReadOnly list_b2 As String = "1|3|5"
Private ReadOnly list_b3 As String = "2|4|6|8"
Private ReadOnly list_b4 As String = "7|9"
Private Sub Form1_Load(sender As Object, e As EventArgs)
C1FlexGrid1.Styles.Add("Combo1")
C1FlexGrid1.Styles("Combo1").ComboList = list_a
C1FlexGrid1.Styles.Add("Combo2")
C1FlexGrid1.Styles("Combo2").ComboList = list_b1
C1FlexGrid1.Cols(1).Style = C1FlexGrid1.Styles("Combo1")
C1FlexGrid1.Cols(2).Style = C1FlexGrid1.Styles("Combo2")
End Sub
Private Sub C1FlexGrid1_BeforeEdit(sender As Object, e As C1.Win.C1FlexGrid.RowColEventArgs)
If e.Col = 2 Then
If IsNothing(C1FlexGrid1(e.Row, 1)) Then
C1FlexGrid1.Cols(2).Style.ComboList = list_b1
ElseIf C1FlexGrid1(e.Row, 1).ToString() = "a" Then
C1FlexGrid1.Cols(2).Style.ComboList = list_b2
ElseIf C1FlexGrid1(e.Row, 1).ToString() = "b" Then
C1FlexGrid1.Cols(2).Style.ComboList = list_b3
ElseIf C1FlexGrid1(e.Row, 1).ToString() = "c" Then
C1FlexGrid1.Cols(2).Style.ComboList = list_b4
End If
End If
End Sub
Private Sub C1FlexGrid1_CellChanged(sender As Object, e As C1.Win.C1FlexGrid.RowColEventArgs)
If e.Col = 1 Then
C1FlexGrid1(e.Row, 2) = Nothing
End If
End Sub
◎サンプルコード(C#)
private readonly string list_a = "a|b|c";
private readonly string list_b1 = " ";
private readonly string list_b2 = "1|3|5";
private readonly string list_b3 = "2|4|6|8";
private readonly string list_b4 = "7|9";
private void Form1_Load(object sender, EventArgs e)
{
c1FlexGrid1.Styles.Add("Combo1");
c1FlexGrid1.Styles["Combo1"].ComboList = list_a;
c1FlexGrid1.Styles.Add("Combo2");
c1FlexGrid1.Styles["Combo2"].ComboList = list_b1;
c1FlexGrid1.Cols[1].Style = c1FlexGrid1.Styles["Combo1"];
c1FlexGrid1.Cols[2].Style = c1FlexGrid1.Styles["Combo2"];
}
private void c1FlexGrid1_BeforeEdit(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
if (e.Col == 2)
{
if (c1FlexGrid1[e.Row, 1] == null)
c1FlexGrid1.Cols[2].Style.ComboList = list_b1;
else if (c1FlexGrid1[e.Row, 1].ToString() == "a")
c1FlexGrid1.Cols[2].Style.ComboList = list_b2;
else if (c1FlexGrid1[e.Row, 1].ToString() == "b")
c1FlexGrid1.Cols[2].Style.ComboList = list_b3;
else if (c1FlexGrid1[e.Row, 1].ToString() == "c")
c1FlexGrid1.Cols[2].Style.ComboList = list_b4;
}
}
private void c1FlexGrid1_CellChanged(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
if (e.Col == 1)
{
c1FlexGrid1[e.Row, 2] = null;
}
}
private readonly string list_b1 = " ";
private readonly string list_b2 = "1|3|5";
private readonly string list_b3 = "2|4|6|8";
private readonly string list_b4 = "7|9";
private void Form1_Load(object sender, EventArgs e)
{
c1FlexGrid1.Styles.Add("Combo1");
c1FlexGrid1.Styles["Combo1"].ComboList = list_a;
c1FlexGrid1.Styles.Add("Combo2");
c1FlexGrid1.Styles["Combo2"].ComboList = list_b1;
c1FlexGrid1.Cols[1].Style = c1FlexGrid1.Styles["Combo1"];
c1FlexGrid1.Cols[2].Style = c1FlexGrid1.Styles["Combo2"];
}
private void c1FlexGrid1_BeforeEdit(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
if (e.Col == 2)
{
if (c1FlexGrid1[e.Row, 1] == null)
c1FlexGrid1.Cols[2].Style.ComboList = list_b1;
else if (c1FlexGrid1[e.Row, 1].ToString() == "a")
c1FlexGrid1.Cols[2].Style.ComboList = list_b2;
else if (c1FlexGrid1[e.Row, 1].ToString() == "b")
c1FlexGrid1.Cols[2].Style.ComboList = list_b3;
else if (c1FlexGrid1[e.Row, 1].ToString() == "c")
c1FlexGrid1.Cols[2].Style.ComboList = list_b4;
}
}
private void c1FlexGrid1_CellChanged(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
if (e.Col == 1)
{
c1FlexGrid1[e.Row, 2] = null;
}
}
旧文書番号
81440