[GcSpreadSheet] セルの編集開始時/終了時に発生するイベントを追加する方法

文書番号 : 85888     文書種別 : 使用方法     登録日 : 2020/08/12     最終更新日 : 2020/08/12
文書を印刷する
対象製品
SPREAD for WPF 3.0J
詳細
セルの編集が開始されるタイミング、または編集が終了するタイミングで処理を実装する場合は、以下のように、カスタマイズしたセル型を作成し、編集エディタのLoadedイベント、またはUnloadedイベントを追加することで対応が可能です。

◎サンプルコード(VB)
Imports GrapeCity.Wpf.SpreadSheet
Imports GrapeCity.Wpf.SpreadSheet.CellType
Imports GrapeCity.Wpf.SpreadSheet.CellType.Editors

Class MainWindow
    Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
        Dim textCellType As MyTextCellType = New MyTextCellType
        GcSpreadSheet1.Workbook.ActiveSheet.Columns(0).CellType = textCellType
    End Sub
End Class

Friend Class MyTextCellType
    Inherits TextCellType

    Public Overrides Function GetEditingElement(ByVal paintingContext As PaintingContext, ByVal row As Integer, ByVal column As Integer, ByVal paintingData As CellData, ByVal eventArgs As EventArgs) As FrameworkElement
        Dim editor As EditBase = TryCast(MyBase.GetEditingElement(paintingContext, row, column, paintingData, eventArgs), EditBase)
        AddHandler editor.Loaded, AddressOf Editor_Loaded
        AddHandler editor.Unloaded, AddressOf Editor_Unloaded
        Return editor
    End Function

    Private Sub Editor_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Console.WriteLine("Edit Begin")
    End Sub

    Private Sub Editor_Unloaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Console.WriteLine("Edit Completed")
    End Sub
End Class
◎サンプルコード(C#)
using GrapeCity.Wpf.SpreadSheet;
using GrapeCity.Wpf.SpreadSheet.CellType;
using GrapeCity.Wpf.SpreadSheet.CellType.Editors;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        MyTextCellType textCellType = new MyTextCellType();
        gcSpreadSheet1.Workbook.ActiveSheet.Columns[0].CellType = textCellType;
    }
}

internal class MyTextCellType : TextCellType
{
    public override FrameworkElement GetEditingElement(PaintingContext paintingContext, int row, int column, CellData paintingData, EventArgs eventArgs)
    {
        EditBase editor = base.GetEditingElement(paintingContext, row, column, paintingData, eventArgs) as EditBase;
        editor.Loaded += Editor_Loaded;
        editor.Unloaded += Editor_Unloaded;
        return editor;
    }

    private void Editor_Loaded(object sender, RoutedEventArgs e)
    {
        Console.WriteLine("Edit Begin");
    }

    private void Editor_Unloaded(object sender, RoutedEventArgs e)
    {
        Console.WriteLine("Edit Completed");
    }
}