Convert DataGridView Column into Proper Case
I have a datagridview with 4 columns. Column 1 is description and I want to convert this to proper case.
The following code converts text to upper case as I type. Is there a method to make this work with proper case?
Private Sub employeedepartmentdatagridview_EditingControlShowing(ByVal _ sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) _
Handles EmployeeDepartmentDataGridView.EditingControlShowing
If TypeOf e.Control Is TextBox Then
DirectCast(e.Control, TextBox).CharacterCasing = CharacterCasing.Upper
End If
End Sub
This code kinda works. If I enter a description, such as "art department", the description is written to the record. However,the proper case is not set. I set a breakpoint and the code fires, however the change is not made. Then, if I click on another record and then click back to the 1st record, the change is visible.
Private Sub employeedepartmentGridView_CellLeave(ByVal sender As Object, ByVal e As _ System.Windows.Forms.DataGridViewCellEventArgs) Handles _ EmployeeDepartmentDataGridView.CellLeave
If e.ColumnIndex = 1 Then
Me.EmployeeDepartmentDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value =StrConv(Me.EmployeeDepartmentDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value, VbStrConv.ProperCase)
End If
End Sub
Any assistance would be appreciated. As a side note, I am using some code to write changes as the cursor moves from one record in the dataset to the next:
Procedure global variable
Public Class DepartmentForm
Dim UpdatePending As Boolean = False
Private Sub EmployeeDepartmentBindingSource_ListChanged(sender As Object, e As System.ComponentModel.ListChangedEventArgs) Handles EmployeeDepartmentBindingSource.ListChanged
If Me.SupplyRoomDataSet.HasChanges Then
Me.UpdatePending = True
End If
End Sub
Private Sub EmployeeDepartmentDataGridView_RowValidated(sender As Object, e As DataGridViewCellEventArgs) Handles EmployeeDepartmentDataGridView.RowValidated
If UpdatePending Then
Me.EmployeeDepartmentTableAdapter.Update(Me.SupplyRoomDataSet)
Me.UpdatePending = False
End If
End Sub