Solved

right trim a column in a datagridview C#

Posted on 2012-03-15
2
2,120 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
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…

821 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