Solved

right trim a column in a datagridview C#

Posted on 2012-03-15
2
2,066 Views
Last Modified: 2012-05-10
Question 1
I am looking to right trim data in a datagrid view, when I pull text from the database it right pads spaces up to the 255 I have specified (it is free text for the user to enter).  If I RTRIM the data in SQL the column becomes read only.

Question 2
Where is a listing of cell style formats like "C" in the example below ? Is there a "P" for percent, an "S" for string etc... ?  I can find examples of using but not a list of available formats.
Example:
dataGridView.Columns["five_offinvoice"].DefaultCellStyle.Format = "C";
0
Comment
Question by:abrusko
  • 2
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 37728120
For trimming values in gridview follow this code-


private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.RowIndex > -1)
           {
                if (e.Value != null)
               {
                   e.Value = e.Value.ToString().Trim();
                }
           }  
      }
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 37728124
Formatting types: http://msdn.microsoft.com/en-us/library/26etazsy.aspx

How to: Format Data in the Windows Forms DataGridView Control
http://msdn.microsoft.com/en-us/library/f9x2790s.aspx
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
No row return after calling the fillschema method 4 40
Runtime Error 2 28
Entity Framework 7 32
What do you call this line of code in this .NET Core page? 4 27
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

895 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

16 Experts available now in Live!

Get 1:1 Help Now