[GcSpreadGrid] ラジオグループ型セルの選択項目が変更されたときに発生するイベントはありますか?

文書番号 : 85063     文書種別 : 使用方法     登録日 : 2020/03/30     最終更新日 : 2020/03/30
文書を印刷する
対象製品
SPREAD for WPF 3.0J
詳細
GcSpreadGridコントロールには、ラジオグループ型セルの選択項目が変更されたときに発生するイベントはありませんので、EditElementShowingイベントで編集用ラジオグループコントロールを取得し、イベントをハンドルする必要があります。

◎サンプルコード(VB)
Public Sub New()
    InitializeComponent()

    ' ラジオグループ型セルの設定
    Dim rdo As New GrapeCity.Windows.SpreadGrid.RadioGroupCellType()
    rdo.ItemsSource = New MyRadioGroupDataList()
    rdo.SelectedValuePath = "ID"
    rdo.DisplayMemberPath = "Caption"
    rdo.Orientation = Orientation.Horizontal
    GcSpreadGrid1.Columns(0).CellType = rdo
    GcSpreadGrid1.Columns(0).Width = 160
End Sub

Public Class MyRadioGroupData
    Private m_ID As Integer
    Private m_Caption As String

    Public Property ID() As Integer
        Get
            Return m_ID
        End Get
        Set(value As Integer)
            m_ID = value
        End Set
    End Property

    Public Property Caption() As String
        Get
            Return m_Caption
        End Get
        Set(value As String)
            m_Caption = Value
        End Set
    End Property
End Class

Public Class MyRadioGroupDataList
    Inherits List(Of MyRadioGroupData)

    Public Sub New()
        Add(New MyRadioGroupData() With {.ID = 1, .Caption = "保留"})
        Add(New MyRadioGroupData() With {.ID = 2, .Caption = "承認"})
        Add(New MyRadioGroupData() With {.ID = 3, .Caption = "却下"})
    End Sub
End Class

' ラジオグループのイベント関連付け解除
Private Sub GcSpreadGrid1_CellEditEnding(sender As Object, e As GrapeCity.Windows.SpreadGrid.SpreadCellEditEndingEventArgs) Handles GcSpreadGrid1.CellEditEnding
    If TypeOf GcSpreadGrid1(e.Position).InheritedCellType Is GrapeCity.Windows.SpreadGrid.RadioGroupCellType Then
        Dim gcrg As GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement = TryCast(GcSpreadGrid1.EditElement, GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement)
        If gcrg Is Nothing Then
            Return
        End If

        RemoveHandler gcrg.SelectionChanged, AddressOf RadioGroupEdit_SelectionChanged
    End If
End Sub

' ラジオグループのイベント関連付け
Private Sub GcSpreadGrid1_EditElementShowing(sender As Object, e As GrapeCity.Windows.SpreadGrid.EditElementShowingEventArgs) Handles GcSpreadGrid1.EditElementShowing
    If TypeOf e.EditElement Is GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement Then
        Dim gcrg As GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement = TryCast(e.EditElement, GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement)
        If gcrg Is Nothing Then
            Return
        End If

        AddHandler gcrg.SelectionChanged, AddressOf RadioGroupEdit_SelectionChanged
    End If
End Sub

Private Sub RadioGroupEdit_SelectionChanged(sender As Object, e As RoutedEventArgs)
    Dim gcrg As GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement = TryCast(GcSpreadGrid1.EditElement, GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement)
    Console.WriteLine(gcrg.SelectedIndex)
End Sub

◎サンプルコード(C#)
public MainWindow()
{
    InitializeComponent();

    // ラジオグループ型セルの設定
    GrapeCity.Windows.SpreadGrid.RadioGroupCellType rdo = new GrapeCity.Windows.SpreadGrid.RadioGroupCellType();
    rdo.ItemsSource = new MyRadioGroupDataList();
    rdo.SelectedValuePath = "ID";
    rdo.DisplayMemberPath = "Caption";
    rdo.Orientation = Orientation.Horizontal;
    gcSpreadGrid1.Columns[0].CellType = rdo;
    gcSpreadGrid1.Columns[0].Width = 160;

    // イベントの関連付け
    gcSpreadGrid1.CellEditEnding += new EventHandler(gcSpreadGrid1_CellEditEnding);
    gcSpreadGrid1.EditElementShowing += new EventHandler(gcSpreadGrid1_EditElementShowing);
}

public class MyRadioGroupData
{
    public int ID { set; get; }
    public string Caption { set; get; }
}

public class MyRadioGroupDataList : List
{
    public MyRadioGroupDataList()
    {
        Add(new MyRadioGroupData() { ID = 1, Caption = "保留" });
        Add(new MyRadioGroupData() { ID = 2, Caption = "承認" });
        Add(new MyRadioGroupData() { ID = 3, Caption = "却下" });
    }
}

// ラジオグループのイベント関連付け解除
void gcSpreadGrid1_CellEditEnding(object sender, GrapeCity.Windows.SpreadGrid.SpreadCellEditEndingEventArgs e)
{
    if (gcSpreadGrid1[e.Position].InheritedCellType is GrapeCity.Windows.SpreadGrid.RadioGroupCellType)
    {
        GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement gcrg = gcSpreadGrid1.EditElement as GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement;
        if (gcrg == null)
        {
            return;
        }

        gcrg.SelectionChanged -= RadioGroupEdit_SelectionChanged;
    }
}

// ラジオグループのイベント関連付け
void gcSpreadGrid1_EditElementShowing(object sender, GrapeCity.Windows.SpreadGrid.EditElementShowingEventArgs e)
{
    if (e.EditElmeent is GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement)
    {
        GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement gcrg = e.EditElement as GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement;
        if (gcrg == null)
        {
            return;
        }

        gcrg.SelectionChanged += RadioGroupEdit_SelectionChanged;
    }
}

private void RadioGroupEdit_SelectionChanged(object sender, RoutedEventArgs e)
{
    GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement gcrg = gcSpreadGrid1.EditElement as GrapeCity.Windows.SpreadGrid.Editors.RadioGroupEditElement;
    Console.WriteLine(gcrg.SelectedIndex);
}
関連情報