作成日: 2019/03/19 最終更新日: 2019/03/19
文書種別
使用方法
詳細
CellParsingイベントで入力値を判定し、セルの値を元に戻すことが可能です。
[Visual Basic]
[C#]
[Visual Basic]
Imports GrapeCity.Win.MultiRow
Imports GrapeCity.Win.MultiRow.InputMan
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' セル型の作成
Dim dateCell As New GcDateTimeCell()
dateCell.Name = "dateCell"
dateCell.Fields.Clear()
dateCell.Fields.AddRange("yyyy/MM/dd")
dateCell.DisplayFields.Clear()
dateCell.DisplayFields.AddRange("yyyy/MM/dd")
' MultiRowの設定
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {dateCell})
GcMultiRow1.RowCount = 5
GcMultiRow1.SetValue(0, 0, New DateTime(2018, 11, 26))
End Sub
Private Sub GcMultiRow1_CellParsing(sender As Object, e As CellParsingEventArgs) Handles GcMultiRow1.CellParsing
' 日付型セルに不正な値が設定された場合
If e.CellName = "dateCell" Then
Dim grid As GcMultiRow = sender
' セルが編集中の場合
If grid.IsCurrentCellInEditMode Then
' 編集用コントロールに不正な文字列が設定されている場合
If DirectCast(grid.EditingControl, GcDateTimeEditingControl).IsInvalidText Then
' 元の値に戻します
e.Value = grid.GetValue(e.RowIndex, e.CellIndex)
e.ParsingApplied = True
End If
End If
End If
End Sub
End Class
[C#]
using GrapeCity.Win.MultiRow;
using GrapeCity.Win.MultiRow.InputMan;
using System;
using System.Windows.Forms;
namespace sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
gcMultiRow1.CellParsing += gcMultiRow1_CellParsing;
}
private void Form1_Load(object sender, EventArgs e)
{
// セル型の作成
GcDateTimeCell dateCell = new GcDateTimeCell();
dateCell.Name = "dateCell";
dateCell.Fields.Clear();
dateCell.Fields.AddRange("yyyy/MM/dd");
dateCell.DisplayFields.Clear();
dateCell.DisplayFields.AddRange("yyyy/MM/dd");
// MultiRowの設定
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { dateCell});
gcMultiRow1.RowCount = 5;
gcMultiRow1.SetValue(0, 0, new DateTime(2018, 11, 26));
}
private void gcMultiRow1_CellParsing(object sender, CellParsingEventArgs e)
{
// 日付型セルに不正な値が設定された場合
if (e.CellName == "dateCell")
{
GcMultiRow grid = (GcMultiRow)sender;
// セルが編集中の場合
if (grid.IsCurrentCellInEditMode)
{
// 編集用コントロールに不正な文字列が設定されている場合
if((grid.EditingControl as GcDateTimeEditingControl).IsInvalidText)
{
// 元の値に戻します
e.Value = grid.GetValue(e.RowIndex, e.CellIndex);
e.ParsingApplied = true;
}
}
}
}
}
}
旧文書番号
83762