Format to Uppercase in a DataGridView.Column

I want to Format to Uppercase in a DataGridView.Column. I used

DefaultCellStyle  property and put > on it but nothing changed. I don't know what is wrong.

Please help me !

Thanks in advance !



Answer this question

Format to Uppercase in a DataGridView.Column

  • Jeffyoung1234

    Hook the CellFormating event and use String.ToUpper - something like:

    Private
    Sub DataGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting

          If (e.ColumnIndex = 1) Then

                e.Value = e.Value.ToString.ToUpper

          End If

    End Sub



  • Xawe

    Thank you for your answer.

    I did this before but I recived an error message:

    Message="An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object."

    Finally, I made it in this way:

    Private Sub UseriGrid_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles UseriGrid.CellEndEdit

      If e.ColumnIndex = 0 Then

         UseriGrid.CurrentCell.Value = UseriGrid.CurrentCell.Value.ToString.ToUpper

      End If

    End Sub

    Anyway....
    I don't understand why is't an easy way to do this. A property like CharacterCasing ...or why not take the format from DefaultCellStyle.

    Thank you again !


  • Format to Uppercase in a DataGridView.Column