我正在使用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