Solved

C# datagridview row enforcing casing

Posted on 2011-03-07
2
633 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 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now