我正在使用DatagridView工具。在這裏,我正在對列進行手動輸入並將其直接保存到數據庫中。我有5個列,其中3個是字母數字,2個是數字列。如何使用VB.Net在datagridview的特定列中設置單元格格式?
我已經將條件設置爲在EditingControlShowing事件中使用處理程序的數字列。
If grdLedgerDetails.CurrentCell.ColumnIndex = 4 Then
AddHandler CType(e.Control, TextBox).KeyPress, AddressOf TextBox_keyPress
ElseIf grdLedgerDetails.CurrentCell.ColumnIndex = 5 Then
AddHandler CType(e.Control, TextBox).KeyPress, AddressOf TextBox_keyPress
End If
Private Sub TextBox_keyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If Char.IsDigit(CChar(CStr(e.KeyChar))) = False Then e.Handled = True
End Sub
此條件適用。但問題是,這種情況適用於所有列。我只是想讓它在指定的列上工作。
請幫我解決這個問題。
在此先感謝。
是的,它的工作很好 – Shell