This is a migrated thread and some comments may be shown as answers.

TextWrapping=NoWrap not working

7 Answers 188 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
lee_bnsf
Top achievements
Rank 1
lee_bnsf asked on 14 Oct 2009, 09:39 PM
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

7 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 15 Oct 2009, 08:06 AM
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.
0
lee_bnsf
Top achievements
Rank 1
answered on 15 Oct 2009, 02:30 PM
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
0
Rossen Hristov
Telerik team
answered on 15 Oct 2009, 02:41 PM
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.
0
lee_bnsf
Top achievements
Rank 1
answered on 15 Oct 2009, 02:53 PM
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
0
Paolo
Top achievements
Rank 1
answered on 19 Jan 2012, 04:35 PM
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
0
Rossen Hristov
Telerik team
answered on 20 Jan 2012, 09:44 AM
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 >>

0
Paolo
Top achievements
Rank 1
answered on 20 Jan 2012, 01:21 PM
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
Tags
GridView
Asked by
lee_bnsf
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
lee_bnsf
Top achievements
Rank 1
Paolo
Top achievements
Rank 1
Share this question
or