private void DataGrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
int index = this.dgv_Item.DataGrid.Columns["字段名"].Index;
if (this.dgv_Item.DataGrid.CurrentCell.ColumnIndex == index)
{
e.Control.KeyPress += new KeyPressEventHandler(TextBox_KeyPress);
}
}
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar != '.')
{
e.Handled = true;
}
}
本文详细介绍了如何在数据网格中实现字段输入限制,通过监听编辑控件显示事件,为特定字段添加数字输入验证功能。

3281

被折叠的 条评论
为什么被折叠?



