Hallo,
würde gerne in meinem dataGridView eine bestimmten Spalte nur für Zahlen freigeben, was mit folgendem Code auch klappt.
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
| private void dataGridView1_EditingControlShowing_1(object sender, DataGridViewEditingControlShowingEventArgs e) { e.Control.KeyPress -= new KeyPressEventHandler(Column1_KeyPress); if (dataGridView1.CurrentCell.ColumnIndex == 0) { TextBox tb = e.Control as TextBox; if (tb != null) { tb.KeyPress += new KeyPressEventHandler(Column1_KeyPress); } } }
private void Column1_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) { e.Handled = true; } } |
Nur möchte ich auch ein Komma eingeben können was leider nicht klappt.
Könnt ihr mir bitte einen Tipp geben wie ich das hin bekomme.
Vielen Dank im Voraus!!!