Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

right trim a column in a datagridview C#

Posted on 2012-03-15
2
Medium Priority
?
2,321 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 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

916 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