//自定义事件,检测单价的键盘的输入
private void EditingControlPrice_KeyPress(object sender, KeyPressEventArgs e)
{
//e.KeyChar != 8是退格键
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar !='.')
{
e.Handled = true;
MessageBox.Show("请输入数字与小数点");
}
}
//自定义事件,检测数量键盘的输入
private void EditingControlCount_KeyPress(object sender, KeyPressEventArgs e)
{
//e.KeyChar != 8是退格键
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
{
e.Handled = true;
MessageBox.Show("请输入整数");
}
}
private void dgvRepairItem_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
//if(e.Control.c)
//e.CellStyle.BackColor = Color.Red;
if (dgvRepairItem.CurrentCell.ColumnIndex == price_col)
{
//防止事件重复的绑定,出现多次提醒
//e.Control.KeyPress -= new KeyPressEventHandler(EditingControlPrice_KeyPress);
//e.Control.KeyPress -= new KeyPressEventHandler(EditingControlCount_KeyPress);
e.Control.KeyPress += new KeyPressEventHandler(EditingControlPrice_KeyPress);
}
if (dgvRepairItem.CurrentCell.ColumnIndex == count_col)
{
//防止事件重复的绑定,出现多次提醒
//e.Control.KeyPress -= new KeyPressEventHandler(EditingControlCount_KeyPress);
//e.Control.KeyPress -= new KeyPressEventHandler(EditingControlPrice_KeyPress);
e.Control.KeyPress += new KeyPressEventHandler(EditingControlCount_KeyPress);
}
}
private void EditingControlPrice_KeyPress(object sender, KeyPressEventArgs e)
{
//e.KeyChar != 8是退格键
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar !='.')
{
e.Handled = true;
MessageBox.Show("请输入数字与小数点");
}
}
//自定义事件,检测数量键盘的输入
private void EditingControlCount_KeyPress(object sender, KeyPressEventArgs e)
{
//e.KeyChar != 8是退格键
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
{
e.Handled = true;
MessageBox.Show("请输入整数");
}
}
private void dgvRepairItem_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
//if(e.Control.c)
//e.CellStyle.BackColor = Color.Red;
//MessageBox.Show(dgvRepairItem.CurrentCell.ColumnIndex.ToString());
//开始处,删除所有自己添加的事件,防止反复提醒,和应用到其它列
e.Control.KeyPress -= new KeyPressEventHandler(EditingControlCount_KeyPress);
e.Control.KeyPress -= new KeyPressEventHandler(EditingControlPrice_KeyPress);
if (dgvRepairItem.CurrentCell.ColumnIndex == price_col)
{
//防止事件重复的绑定,出现多次提醒
//e.Control.KeyPress -= new KeyPressEventHandler(EditingControlPrice_KeyPress);
//e.Control.KeyPress -= new KeyPressEventHandler(EditingControlCount_KeyPress);
e.Control.KeyPress += new KeyPressEventHandler(EditingControlPrice_KeyPress);
}
if (dgvRepairItem.CurrentCell.ColumnIndex == count_col)
{
//防止事件重复的绑定,出现多次提醒
//e.Control.KeyPress -= new KeyPressEventHandler(EditingControlCount_KeyPress);
//e.Control.KeyPress -= new KeyPressEventHandler(EditingControlPrice_KeyPress);
e.Control.KeyPress += new KeyPressEventHandler(EditingControlCount_KeyPress);
}
}