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

Word Wrap Column Header for AutoGeneratedColumns

5 Answers 368 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 19 Mar 2018, 09:31 PM
How can I achieve the following attached Image in GridView? In the example (https://docs.telerik.com/devtools/wpf/controls/radgridview/columns/column-headers), the data columns are known but in my case, I don't know the column headers to do such example. Any suggestions on how to achieve this?

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 22 Mar 2018, 01:27 PM
Hello Joseph,

Thank you for the provided image.

Though I am not completely sure what your setup is, you should be able to achieve your goal by setting the Header property of a given column programmatically when the needed data is known. Would such an approach be possible for you or I am missing something?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Joseph
Top achievements
Rank 1
answered on 27 Mar 2018, 03:02 PM

Hello Stefan,

Thank you for that suggestion. However, as I've stated, the challenge for me is that the column headers are not known. 

 

In the xaml, here is what I got.

<telerik:RadGridView  x:Name="myDataGrid" ShowGroupPanel="False" IsFilteringAllowed="False" RowIndicatorVisibility="Collapsed" SelectionUnit="Cell" ColumnWidth="120" />

 

Then in the xaml.cs, here is what I got

DataTable dt = new DataTable();
 
foreach (var item in ColumnNames)
{
  dt.Columns.Add(item, typeof(string));
}
 
myDataGrid.AutoGenerateColumns = true;
myDataGrid.ItemsSource = dt.DefaultView;
0
Accepted
Stefan
Telerik team
answered on 29 Mar 2018, 10:52 AM
Hello Joseph,

Since you are using auto generated columns, you can hook up to the AutoGeneratingColumn event of the control. Through the event arguments you can access each column and manipulate its Header property as per your requirements.

Can you please check this out?

Additionally, you can take a look at the Defining Columns help article.

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Joseph
Top achievements
Rank 1
answered on 06 Apr 2018, 10:15 PM

Stefan,

That did it. As a reference for others, here is what I did.

private void myDataGrid_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
       column.HeaderTextAlignment = TextAlignment.Center;
       column.HeaderTextWrapping = TextWrapping.Wrap;
       column.TextWrapping = TextWrapping.Wrap;
       column.Width = 150;
          
}

 

Thank you,

JA

0
Martin Ivanov
Telerik team
answered on 10 Apr 2018, 08:54 AM
Hello Joseph,

Thank you for sharing your solution. 

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Joseph
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Joseph
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or