Solved

C# datagridview row enforcing casing

Posted on 2011-03-07
2
677 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 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