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 7700487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:43:13+00:00 2026-05-31T22:43:13+00:00

As I mentioned in a recent question on how to show strings with carriage

  • 0

As I mentioned in a recent question on how to show strings with carriage returns in a gridview, I also wondered about how to format this particular string differently, on the fly.

The string coming back from the database has carriage returns. It is then directly bound to a GridViewColumn like this:

<GridViewColumn Width="365" Header="Desc" DisplayMemberBinding="{Binding desc}" />

Say I want to remove those carriage returns, using a String.Replace, but without altering the DataTable the gridview is bound to.

I used to do something similar in ASP.net with the Repeater.OnItemDataBound method, applying formatting or the like.

  • 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-31T22:43:14+00:00Added an answer on May 31, 2026 at 10:43 pm

    You would need to make a value converter:

    [ValueConversion(typeof(string), typeof(string))]
    public class ReplaceCarriageReturnConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value as string == null ? string.Empty : (value as string).Replace("\r", " - "); ;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    Declare your converter:

    <local:ReplaceCarriageReturnConverter x:Key="ReplaceCarriageReturnConverter"/>
    

    Modify your binding:

    <GridViewColumn Width="365" Header="Desc" DisplayMemberBinding="{Binding desc, Converter={StaticResource ReplaceCarriageReturnConverter}}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This recent question about sorting randomly using C# got me thinking about the way
I've recent been reading about immutable strings Why can't strings be mutable in Java
This is similar to a recent question. I will be maintaining sorted a list
This is a question from recent GATE entrance exam. A process executes the code
In the recent question How to organize MATLAB code? Andrew Janke mentioned in his
In a recent discussion on ORMs for webapps someone mentioned that there are times
To short version of this question is that I want to accomplish something along
This thread got too confusing (for me) so I am asking the question again.
I've done a series of questions about J2ME Game developing, and in a recent
The question says it all. I can't seem to find any recent rails tutorials

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.