private void InjectionDrugDataGridView_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
DataGridView dgv = (DataGridView)sender;
int cnt = 0;
if (e.RowIndex + 1 > this.injectionDrugDt.Rows.Count)
{
if (string.IsNullOrEmpty(dgv[0, e.RowIndex].Value.ToString()) &&
string.IsNullOrEmpty(dgv[1, e.RowIndex].Value.ToString()) &&
string.IsNullOrEmpty(dgv[2, e.RowIndex].Value.ToString()) &&
string.IsNullOrEmpty(e.FormattedValue.ToString()))
{
// 1行の項目が全て空欄時は入力チェックしない
return;
}
}
switch (e.ColumnIndex)
{
case 0:
// コード
if (!string.IsNullOrEmpty(e.FormattedValue.ToString()))
{
foreach (DataGridViewRow drs in dgv.Rows)
{
if (drs.Cells[0].Value == null)
{
// コードがNULLの場合(新規行)、重複カウントしない
continue;
}
if (drs.Cells[0].Value.ToString() == e.FormattedValue.ToString() &&
e.RowIndex != drs.Index)
{
// 自身以外の行で判定
cnt++;
}
}
if (cnt > 0)
{
// 重複行あり
Log.Error(Resources.LEM_401, null, null, this.GetClassName());
MsgBoxForm msgForm = new MsgBoxForm(string.Format
(Properties.Resources.EM_117, e.FormattedValue), MsgType.Error, true);
msgForm.ShowDialog();
e.Cancel = true;
}
}
break;
}
}