Solved

C# datagridview row enforcing casing

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating a flowchart from an algorithm 5 30
Check my code out(2) 2 53
C# TextBox 11 30
Resolve Dependency Issues 4 45
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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

20 Experts available now in Live!

Get 1:1 Help Now