Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7058699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:08:38+00:00 2026-05-28T04:08:38+00:00

I have a datagridview being populated by a collection of objects. the values within

  • 0

I have a datagridview being populated by a collection of objects.
the values within the first column are similar to:

“SOMEDISPLAYTEXT#T:\blasndw\lwwdjawn\wjnawdja”

“somedisplaytext#T:\kndwla\igrhysbv\kjnfak”

I do not wish to wish to change these values, as i am also constantly updating them, however, i wish the datagridview to only show the first part of this string ‘somedisplaytext’, up to but not including the ‘#’ ..without changing the underlying values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:08:38+00:00Added an answer on May 28, 2026 at 4:08 am

    If you use WinForms:

    According to MSDN ( http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellformatting.aspx ), you can handle the CellFormating event of a DataGridView and then change the way the value is formatted.

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        // If the column is the Artist column, check the
        // value.
        if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Artist")
        {
            if (e.Value != null)
            {
                // Check for the string "pink" in the cell.
                string stringValue = (string)e.Value;
                stringValue = stringValue.ToLower();
                if ((stringValue.IndexOf("pink") > -1))
                {
                    e.CellStyle.BackColor = Color.Pink;
                }
    
            }
        }
        else if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Release Date")
        {
            ShortFormDateFormat(e);
        }
    }
    

    This first method will change the background color if the column Artist contains “pink”, and will change the format of the values in the column “Release Date” with the below method:

    You can see here that you just have to replace the Value property of the DataGridViewCellFormattingEventArgs

    //Even though the date internaly stores the year as YYYY, using formatting, the
    //UI can have the format in YY.  
    private static void ShortFormDateFormat(DataGridViewCellFormattingEventArgs formatting)
    {
        if (formatting.Value != null)
        {
            try
            {
                System.Text.StringBuilder dateString = new System.Text.StringBuilder();
                DateTime theDate = DateTime.Parse(formatting.Value.ToString());
    
                dateString.Append(theDate.Month);
                dateString.Append("/");
                dateString.Append(theDate.Day);
                dateString.Append("/");
                dateString.Append(theDate.Year.ToString().Substring(2));
                formatting.Value = dateString.ToString();
                formatting.FormattingApplied = true;
            }
            catch (FormatException)
            {
                // Set to false in case there are other handlers interested trying to
                // format this DataGridViewCellFormattingEventArgs instance.
                formatting.FormattingApplied = false;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView being regularly populated via data-bound objects, and the number of
I currently have a 2-column wide DataGridView, the first column being a DataGridViewTextBoxColumn and
I have a DataGridView on my Form which is being populated with database records
In a datagridview, I have counters being updated starting from zero via messages being
I have a datagridview where the default values are provided for every new row
I have a DataGridView with one DataGridViewComboBoxColumn in my WinForms application. I need to
I have a datagridview where the users can select which subset of columns to
I have a DataGridView with its datasource set to a generic list of custom
I have a DataGridView that I want to query using Linq (C# WinForm). I
I have a datagridview which im binding DataTable to. What I want do is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.