DataGridView控件单元格输入时控制大小写
通过事件EditingControlShowing事件实现
Private Sub xDataGridView_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles xDataGridView.EditingControlShowing
If (TypeOf e.Control Is DataGridViewTextBoxEditingControl) Then
Dim pControl As DataGridViewTextBoxEditingControl = e.Control
If (xDataGridView.CurrentCell.ColumnIndex = MCommandColumn.Index) Then
pControl.CharacterCasing = CharacterCasing.Upper
End If
End If
End Sub
之前的实现方法,效果不是很好
Private Sub xDataGridView_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles xDataGridView.CellEndEdit
If (e.ColumnIndex = MCommandColumn.Index) Then
Dim pValue As Object = xDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
If (pValue IsNot Nothing) Then
xDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = Convert.ToString(pValue).ToUpper()
End If
End If
End Sub