Avatar of rwheeler23
rwheeler23
Flag for United States of America asked on

What is the proper way to force uppercase on a column in a datagridview?

I have a C# program with a datagridview with 12 columns.  On column [2] I want to force uppercase so the data will not only always display as uppercase but will be written in uppercase.

                dgvViewJobLinker.Columns[2].Width = 100;
                dgvViewJobLinker.Columns[2].ReadOnly = false;
                dgvViewJobLinker.Columns[2].HeaderText = "Transfer to Job";

What is the proper way to force uppercase on a column in a datagridview?
C#

Avatar of undefined
Last Comment
rwheeler23

8/22/2022 - Mon
Ryan Chong

I want to force uppercase so the data will not only always display as uppercase but will be written in uppercase.


if you mean to update the data to upper case before the display? I think this already answered your question above?

rwheeler23

ASKER
If a user type 2136d8 i want it to immediately display 2136D8. I was able to get it to display uppercase but only after the user exited the field.
Ryan Chong

I was able to get it to display uppercase but only after the user exited the field.

what's the application platform that you're using? Web Form, Windows Application, etc? you probably need to hook into the onchange or keydown/keypress event to change the text to uppercase.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
rwheeler23

ASKER
This is a winform. I think keypress may be the way to go.
Ryan Chong

My bad, it's no longer that difficult to set it up, so we just need to update the CharacterCasing property to Upper

Untitled.jpg
rwheeler23

ASKER
The problem I have is i am dealing with a column in a datagridview not a textbox. I wish this was a property of a datagridview.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Ryan Chong

in that case, probably the easiest way will be format the data at backend (SQL), so from front end (datagridview) just display the data.
rwheeler23

ASKER
The problem there is I use _commandbulder to write the data so I do write the data as a group. The column in question is blank to start and then the users can start filling in the  blanks. I will play around with some change event or keypress to force uppercase as the user types.
ASKER CERTIFIED SOLUTION
it_saige

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
rwheeler23

ASKER
OK, this was helpful for the display on the screen  however what is written to the database are the lowercase values.  I have a Save button at the bottom of this dgv. I am going to put a loop under this save button to uppercase all values in column [1].  This what I got to work.

        private void dgvViewJobLinker_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            // Check the value of the e.ColumnIndex property if you want to apply this formatting only so some columns.
            if (e.ColumnIndex == 1)
            {
                e.Value = e.Value.ToString().ToUpper();
                e.FormattingApplied = true;
            }
        }
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
rwheeler23

ASKER
Thanks for these tips. They got me pointed in the right direction.