Solved

C# datagridview row enforcing casing

Posted on 2011-03-07
2
668 Views
Last Modified: 2012-05-11
Based on somebody's answer to a previous question, I enforce character casing in datagridview cells as seen in the attached code.

Now I need to selectively enforce casing.  That is, for colDesc1 I don't want to enforce casing whereas for colItemNo I do want to enforce casing.

I can't find a way to do this.  I tried e.Control.Name, but it is an empty string.  I noticed e.Control.Tag, but cannot assign a tag in the datagridview interface.  I tried e.Control.Location, but that didn't work.

Any suggestions?
private void dgvMain_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control is TextBox)
                ((TextBox)e.Control).CharacterCasing = CharacterCasing.Upper;
        }

Open in new window

0
Comment
Question by:g_johnson
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35063283
What about expanding the code to this:
private void dgvMain_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    DataGridView grid = sender as DataGridView;

    if (grid.SelectedColumns[0].Name == "colItemNo" && e.Control is TextBox)
        ((TextBox)e.Control).CharacterCasing = CharacterCasing.Upper;
}

Open in new window

0
 
LVL 4

Author Comment

by:g_johnson
ID: 35071729
I was not able to use SelectedColumns[0] (apparently it's not set), but I was able to use ColumnIndex to get where I was going.

thanks for the help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question