TextWrapping=NoWrap not working

8 posts, 0 answers
  1. lee_bnsf
    lee_bnsf avatar
    16 posts
    Member since:
    Apr 2007

    Posted 14 Oct 2009 Link to this post

    Hi, I'm using internal build 925.  In the RadGridView, I have the following column definition:

    <telerikGridView:GridViewDataColumn x:Name="colDetails" Header="Details" DataMemberBinding="{Binding Details}"
     Width="100" IsGroupable="False" TextWrapping="NoWrap" 
    ShowDistinctFilters="False" IsResizable="False" /> 

    I would like for the text to be cut off and the height of the row to be the height of a single line, but instead the text is wrapping and the row is as tall as the text.  Is there another property that I'm missing?

    Thanks,

    Lee
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2477 posts

    Posted 15 Oct 2009 Link to this post

    Hi lee_bnsf,

    I have prepared a small sample project with the 925 binaries in order to reproduce this behavior, but I could not. I have attached the sample project. Can you please run it on your end and see whether the wrapping works as expected or not on your end. It works on my end. There are two identical grids in my project -- one has the wrapping turned off and the other does not.

    Can you please examine my project and see what is the difference between my sample project and yours? This will help us identify the problem.

    Kind regards,
    Ross
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. lee_bnsf
    lee_bnsf avatar
    16 posts
    Member since:
    Apr 2007

    Posted 15 Oct 2009 Link to this post

    Hi Ross,

    Your sample worked as expected, until I added a line feed to the data.  My data has line feeds and this is what is causing the cell to grow.

    Any suggestions or workarounds?

    Thanks,

    Lee
  4. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2477 posts

    Posted 15 Oct 2009 Link to this post

    Hi lee_bnsf,

    In this case you will need to remove the line feeds from your data before feeding it to the grid. You can create another string property that will return the original text but will do something like this before:

    static string GetNormalizedText(string text)
    {
        const char ReplacementChar = '\uFFFD';
     
        StringBuilder sb = new StringBuilder(text);
        sb.Replace(Environment.NewLine, "" + ReplacementChar);
        sb.Replace('\n', ReplacementChar);
        sb.Replace('\r', ReplacementChar);
        return sb.ToString();
    }

    \uFFFD is the Unicode Replacement Character, but you can use a simple space if you need to.   

    I hope this helps.

    Sincerely yours,
    Ross
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. lee_bnsf
    lee_bnsf avatar
    16 posts
    Member since:
    Apr 2007

    Posted 15 Oct 2009 Link to this post

    Ok.  Not the biggest fan of this solution, but it will work for now.  What we really need is an AutoGrow property that will control whether or not the cell will expand to accomodate the text.

    Thanks!
    Lee
  6. Paolo
    Paolo avatar
    2 posts
    Member since:
    Jan 2012

    Posted 19 Jan 2012 Link to this post

    Hi guys... I have the same problem explained in this post: a GridViewDataColumn contains line feeds and grid row grows accordingly.
    What about new solutions? No additional properties have been added to GridView in order to handle this situations?

    Thanks in advance

    Paolo
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2477 posts

    Posted 20 Jan 2012 Link to this post

    Hi,

    We do not have the right to tamper with the original string that you provide to RadGridView. If you want it to be without line feeds then you will need to remove them before you pass it in. RadGridView does not posses artificial intelligence which can change text like this. And it is not its job to do that anyway.

    All the best,
    Ross
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Paolo
    Paolo avatar
    2 posts
    Member since:
    Jan 2012

    Posted 20 Jan 2012 Link to this post

    Hi Ross,

    thanks for your answer. I know GridView has no "artificial intelligence", as you say... I was only wondering if any additional property was added to handle a known issue :)
    Anyway, I found a working solution following your hint and adding this kind of property in my own GridViewDataColumn 
    :

    public class MyGridViewDataColumn : GridViewDataColumn
    {
     [...]

    #region AcceptsReturn
    /// <summary>
    /// Default true. Set it to false if you want to prevent grid row growing due to line feeds.
    /// Warning: setting this property to false will overwrite the existing converter (if any).
    /// </summary>
    public bool AcceptsReturn
    {
        get { return (bool)GetValue(AcceptsReturnProperty); }
        set { SetValue(AcceptsReturnProperty, value); }
    }
     
    public static readonly DependencyProperty AcceptsReturnProperty =
        DependencyProperty.Register("AcceptsReturn", typeof(bool), typeof(MyGridViewDataColumn), new System.Windows.PropertyMetadata(true, AcceptsReturnPropertyChangedCallback));
     
    private static void AcceptsReturnPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var inst = d as MyGridViewDataColumn;
        bool acceptsReturn = (bool)e.NewValue;
     
        if (inst != null && inst.DataMemberBinding != null)
        {
            inst.DataMemberBinding.Converter = (acceptsReturn) ? null : new StringLineFeedsConverter();
        }       
    }
     
    /// <summary>
    /// A custom converter to parse data content and remove line feeds.
    /// </summary>
    public class StringLineFeedsConverter : IValueConverter
    {
        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string text = (string)value;
            StringBuilder sb = new StringBuilder(text);
            sb.Replace(Environment.NewLine, " ");
            sb.Replace('\n', ' ');
            sb.Replace('\r', ' ');
            return sb.ToString();
        }
     
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
        #endregion
    }
     
    #endregion

    }

    Hope this helps anyone needs a similar behaviour.
    All the best,

    Paolo
Back to Top