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

[Solved] Wrap Grid Header Text for All Columns Programmatically

3 Answers 292 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.
Leslie
Top achievements
Rank 1
Leslie asked on 01 Oct 2010, 12:49 AM
Where can I intercede in the grid creation process to set all columns to wrap?  I tried Grid.Loaded and that had no effect.

This is my code:

	foreach (var col in this.Columns)
col.TextWrapping = TextWrapping.Wrap;

Thank you,

Leslie

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 01 Oct 2010, 12:36 PM
Hi Leslie,

 This setting is for data cells - if you want to apply wrapping for column header you add TextBlock in the Header property and set TextWrapping for this TextBlock. For example:

var c = new GridViewColumn();
c.Header = new TextBlock() { Text = "MyHeader", TextWrapping = System.Windows.TextWrapping.Wrap };


Kind regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Leslie
Top achievements
Rank 1
answered on 01 Oct 2010, 04:25 PM
So I tried the following, and it had no effect, it even ignored my widths on the columns.  I tried it with and without setting the width on the textblock.

private void CmpDataGrid_Loaded(object sender, RoutedEventArgs e)
{
    if (WrapHeaderText)
foreach (var col in this.Columns)
    if (col.Header is string && col.Width.Value > 1) 
col.Header = new TextBlock() { Text = col.Header.ToString(), TextWrapping = System.Windows.TextWrapping.Wrap, Width = col.Width.Value };
}

Leslie
0
Leslie
Top achievements
Rank 1
answered on 01 Oct 2010, 05:32 PM
ok, I take it back!  Sorry!  I had my width set too wide! :o

Thank you very much!

Leslie
Tags
GridView
Asked by
Leslie
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Leslie
Top achievements
Rank 1
Share this question
or