hope below code can help you in restricting datagridview
private void dtgView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (this.dtgView.CurrentCell.ColumnIndex == dtgView.Columns["Column2"].Index & (e.Control != null))
{
TextBox tb = (TextBox)e.Control;
tb.KeyPress += TextBox_KeyPress;
}
}
private void TextBox_KeyPress(System.Object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (((TextBox)sender).Text == string.Empty & e.KeyChar == (char) 46)
{
e.Handled = true;
return;
}
if (((TextBox)sender).Text.Contains(Convert.ToString((char)46)) & e.KeyChar == (char)46)
{
e.Handled = true;
return;
}
if (!(e.KeyChar == 44) & !(e.KeyChar == 45))
{
if ((!(char.IsDigit(e.KeyChar) | char.IsControl(e.KeyChar) | (e.KeyChar == (char)46))))
{
e.Handled = true;
}
}
}