۰۵-آبان-۱۳۹۲, ۰۹:۲۲:۳۵
سلام دوستان گلم امروز میخوام نحوه تایپ فقط عدد در سلول های مورد نظر Data Grid view رو بهتون آموزش بدم.
1 - یه دیتا گرید ویو رو فرم قرار بدید
2- و توی قسمت CellValidating کد زیر رو بنویسید
1 - یه دیتا گرید ویو رو فرم قرار بدید
2- و توی قسمت CellValidating کد زیر رو بنویسید
کد:
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = "";
int newInteger;
// Don't try to validate the 'new row' until finished
// editing since there
// is not any point in validating its initial value.
if (dataGridView1.Rows[e.RowIndex].IsNewRow || e.ColumnIndex != dataGridView1.Columns[شماره ستون کد کالا].Index) { return; }
if (!int.TryParse(e.FormattedValue.ToString(),
out newInteger) || newInteger < 0)
{
e.Cancel = true;
dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer";
}
}