Upper Case Letters in DataGrid  
Author Message
Deeps_123





PostPosted: Visual C# General, Upper Case Letters in DataGrid Top

I am a newbie in C# . I have a datagrid control and i want my user to enter only upper case letters. I dont know how to do it. Please help me out.

Thanks in advance



Visual C#18  
 
 
TaylorMichaelL





PostPosted: Visual C# General, Upper Case Letters in DataGrid Top

When you post a question about the data grid please be sure to mention whether it is web or WinForms as the control exists in both but is not the same. Additionally be aware that in v2 an entirely new set of grid controls were introduced but they are still often referred to as a data grid.

If you have a DataGrid with a DataGridTextBoxColumn then you will need to get access to the underlying DataGridTextBox after it is created. You can then set the CharacterCasing property to force it to upper case. You will need to wait until the control is created either initially or after data binding occurs so you'll need to handle the appropriate event in the grid. This is for WinForms only.

The web version does not expose a text box at all. Even if it did the TextBox class does not support casing. Therefore you'll have to create a template column that shows a custom text box when in edit mode. You'll need to use scripting on the client to uppercase letters as the user types. You'll then need to hook the text change notification on the client to run your script.

For v2 with the GridView for web apps you are basically in the same boat. The BoundColumn does support a formatting string but I'm not aware of a format specifier that will upper case a string. You could write one though. If you go this route be sure to set the ApplyFormatInEditMode( ) so the formatting applies in both read-only and edit mode. You could also create your own column deriving from DataControlField.

The DataGridView for WinForms is like the GridView. You have to set the formatting option for the column but you'll have to create the format string first. You can also create your own text box column deriving from DataGridViewColumn.

Michael Taylor - 12/13/06