Solved

right trim a column in a datagridview C#

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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 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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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