ستون عددی در دیتاگرید ویو
با استفاده از کد زیر می توان یک ستون در دیتاگرید ویو را به شکلی تغییر داد که فقط ورودی عددی قبول کند . برای اینکار از رویداد EditingControlShowing استفاده می کنیم ، مثلا در کد زیر ما ستون اول دیتاگریدویو محدود به مقادیر عددی کرده ایم .
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { e.Control.KeyPress -= DatagridviewCell_KeyPress; if (this.dataGridView1.CurrentCell.ColumnIndex == this.dataGridView1.Columns[0].Index) { e.Control.KeyPress += DatagridviewCell_KeyPress; } } private void DatagridviewCell_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar)) { e.Handled = true; } }