none
DataGridView -- setting column format to 'UpperCase'

    Question

  • Hi. 

    I'm using VC# with VS2005

    How do is set an individual column on a DataGridView so that it converts all input to UpperCase (I tried editing the column and setting the format to 'ToUpper' and to 'UCase', but no luck....)

    Also, how could I set the format specifier to limit a column's input to numbers only?

    Thank you.


    John F.

    Tuesday, November 28, 2006 4:19 AM

Answers

  • You can set the cell charactercasing in the EditingControlShowing event.  The CellFormat is a good place to make sure all the text is upper case

     

     

    Code Snippet

            private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                e.Value=e.Value.ToString().ToUpper();
                e.FormattingApplied = true;
            }

            private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                TextBox txt = e.Control as TextBox;
                if (txt != null)
                {
                    txt.CharacterCasing = CharacterCasing.Upper;
                }
            }

     


     

    Sunday, May 13, 2007 2:05 AM

All replies

  • Did you ever figure this out?  I am having this issue myself and need some help. 

     

    Thanks

     

    T

    Friday, May 11, 2007 2:34 PM
  • You can set the cell charactercasing in the EditingControlShowing event.  The CellFormat is a good place to make sure all the text is upper case

     

     

    Code Snippet

            private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                e.Value=e.Value.ToString().ToUpper();
                e.FormattingApplied = true;
            }

            private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                TextBox txt = e.Control as TextBox;
                if (txt != null)
                {
                    txt.CharacterCasing = CharacterCasing.Upper;
                }
            }

     


     

    Sunday, May 13, 2007 2:05 AM