私はいくつかの列で無制限DataGridView
を持っています。関数を作成しましたが、CellValidating
うまく機能します。現在、テキスト ファイルからデータを読み込んで、DataGridView
. ただし、これを行うと、CellValidating
関数が呼び出されることはありません。このように入力されたデータを検証することは可能ですか?
編集:ここに私のCellValidate
機能の一部があります:
private void Grid_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
string headerText = Grid.Columns[e.ColumnIndex].HeaderText;
switch (headerText)
{
case "Number":
if (!String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
if (!Regex.IsMatch(e.FormattedValue.ToString(), @"(^\d{1,2}$)"))
{
MessageBox.Show("Number must be a 1 or 2 digit positive number");
e.Cancel = true;
}
}
}
}