發表文章

目前顯示的是 1月, 2014的文章

[VB.Net]DataGridView 某欄 限制只能輸入數字

'限制不能輸入數字以外的字元 Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing bt_Save.Text = DataGridView1.CurrentCell.ColumnIndex If DataGridView1.CurrentCell.ColumnIndex = 3 Then '欄位索引3 Dim EditCell As DataGridViewTextBoxEditingControl EditCell = CType(e.Control, DataGridViewTextBoxEditingControl) EditCell.SelectAll() AddHandler EditCell.KeyPress, AddressOf Cells_KeyPress End If End Sub Private Sub Cells_KeyPress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) If e.KeyChar <> Chr(8) And e.KeyChar <> Chr(13) And (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) Then Beep() Beep() e.KeyChar = Chr(0) End If End Sub