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!

4

2 回答 2

1

您可以创建DataGridTextBoxColumn此处显示的自定义:

如何通过添加新属性将 DataGridView 列文本格式设置为大写?

于 2017-06-30T18:50:40.190 回答
1

只是为了结束这个线程,我使用了原始问题中的代码。我想这是在 DataGridView 控件中设置大小写的最简单方法。

于 2017-06-30T23:23:37.960 回答