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

Setting header width/text wrapping for dynamically created columns

2 Answers 139 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gilles
Top achievements
Rank 1
Gilles asked on 08 Sep 2010, 09:11 PM
Hello,

I have a RadGridView for which the columns are generated dynamically at run-time.

I need to have the columns be as wide as they need to be for the cell's content but wrap on the column headers so the header text does not define the column width.

I have seen a similar post on these forums but the columns were defined in the Xaml, and the headers contained TextBlock.

In my case, the columns are created during the AutoGeneratingColumn event. As for the headers they are created this way:

private void dg_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)   
{
    e.Column.Header = GetHeaderName(e.Column.UniqueName); 
}

Where GetHeaderName returns a string.

2 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 09 Sep 2010, 07:23 AM
Hello,

 You can add TextBlock or any other UI component programmatically as well to the column Header property. 

Sincerely yours,
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
Gilles
Top achievements
Rank 1
answered on 09 Sep 2010, 02:56 PM
It worked, I created a TextBlock with TextWrapping and added :

 

 

 

e.Column.Width = GridViewLength.SizeToCells;

So the cells were the correct size.

I'm not happy with the wrapping algorythm, but that's a .Net problem rather than a Telerik one.

 

 

 

 

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