1

My form contains several DataGridView controls that have two columns. I want the data that the user types into column 1 to be converted to upper case. The data in column 0 is read only and is populated by my program. It is numeric and does not need to be converted to upper case. The code below works but I'm wondering if there's a better way.

private: System::Void dataGridView_patterns_EditingControlShowing(System::Object^  sender, System::Windows::Forms::DataGridViewEditingControlShowingEventArgs^  e)
    {
        // This event sets the character casing to upper for the patterns.  It is called once per pattern.

        TextBox^ myControl;

        myControl = (TextBox^)(e->Control);
        myControl->CharacterCasing = CharacterCasing::Upper;
    }

The only problem that I have with this code is that the EditingControlShowing event is called once for every row in the DataGridView. Is there a way to set the CharacterCasing to Upper one time for the control, or does it have to be set for every row to work properly? I don't notice any performance issues, but it just seems unnecessary to set the casing for every row in the control.

Thank you!

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Dan Z
  • 101
  • 13

2 Answers2

1

You can create a custom DataGridTextBoxColumn shown here:

How to set DataGridView columns text format to uppercase by adding new property?

jaredbaszler
  • 3,941
  • 2
  • 32
  • 40
  • Hi Jared, Thanks for your answer. I actually read that thread before I posted my question. It seemed like a lot of work with no payback. I'm surprised that Microsoft doesn't provide a CharacterCasing Property for the columns of a DataGridView. The best place to program it would be in the Edit Columns dialogue of the DataViewGrid control. Oh well preaching to the choir I'm sure. :o) Thanks again for taking the time to review and respond to my question. – Dan Z Jun 30 '17 at 23:21
1

Just to close out this thread, I used the code in my original question. I guess that's the easiest way to set the casing in a DataGridView control.

Dan Z
  • 101
  • 13