セルの編集時にGcNumberCellの値をnullにするには?

文書番号 : 40527     文書種別 : 使用方法     登録日 : 2017/07/26     最終更新日 : 2017/07/26
文書を印刷する
対象製品
MultiRow for Windows Forms 10.0J
詳細
セルの編集時にNumericUpDownCellの値を選択し、[Delete]キーや[BackSpace]キーで削除するとNumericUpDownCellの値はnull(Visual BasicではNothing)になります。一方、GcNumberCellでは値が0となります。
GcNumberCellでNumericUpDownCellと同様の結果を提供するには、次のようにコーディングします。

[Visual Basic]
Imports GrapeCity.Win.MultiRow
Imports InputManCell = GrapeCity.Win.MultiRow.InputMan
Imports GrapeCity.Win.Editors

Private Sub GcMultiRow1_EditingControlShowing(ByVal sender As System.Object, ByVal e As EditingControlShowingEventArgs) Handles GcMultiRow1.EditingControlShowing
    Dim gcMultiRow As GcMultiRow = TryCast(sender, GcMultiRow)
    If TypeOf gcMultiRow.CurrentCell Is InputManCell.GcNumberCell Then
        RemoveHandler e.Control.KeyUp, AddressOf GcNumber_KeyUp
        AddHandler e.Control.KeyUp, AddressOf GcNumber_KeyUp
    End If
End Sub

Private Sub GcNumber_KeyUp(ByVal sender As System.Object, ByVal e As KeyEventArgs)
    Dim gcNumber As GcNumber = TryCast(sender, GcNumber)
    If (e.KeyData = Keys.Delete Or e.KeyData = Keys.Back) And gcNumber.Text = "0" Then
        e.Handled = True
        gcNumber.Clear()
    End If
End Sub

[C#]
using GrapeCity.Win.MultiRow;
using InputManCell = GrapeCity.Win.MultiRow.InputMan;
using GrapeCity.Win.Editors;

private void gcMultiRow1_EditingControlShowing(object sender, EditingControlShowingEventArgs e)
{
    GcMultiRow gcMultiRow = sender as GcMultiRow;

    if (gcMultiRow.CurrentCell is InputManCell.GcNumberCell)
    {
        e.Control.KeyUp -= new KeyEventHandler(gcNumber_KeyUp);
        e.Control.KeyUp += new KeyEventHandler(gcNumber_KeyUp);
    }
}

private void gcNumber_KeyUp(object sender, KeyEventArgs e)
{
    GcNumber gcNumber = sender as GcNumber;
    if ((e.KeyData == Keys.Delete || e.KeyData == Keys.Back) && gcNumber.Text == "0")
    {
        e.Handled = true;
        gcNumber.Clear();
    }
}