May 6, 2011

Having column display name in RadGrid Column chooser but not in the header of the grid

A little bit of background for this one.

I had a Telerik RadGrid that was having few columns ...

It had the column chooser enabled. Few of the columns were icons (for example “Answered”, “Rating”).

I wanted to have them without header text so I added the Template column and everything was just fine.

Until I right clicked on the header in order to show the column chooser. It was displaying the columns with auto generated names like “GridTemplateColumn7”, “GridTemplateColumn10”.

My goal was to keep the header of the grid clean (e.g. no label) because the icons were 16x16 and that’s all the space I needed to occupy with those columns, having a header “Answered” would extend the entire column. So to solve this case here is what I did:

Solution:

1. Added header text to the column and saw that the header text is appearing in the column chooser.

2. To hide it from the header of the column I added an empty <HeaderTemplae>.

The column should look like this:

<telerik:GridTemplateColumn HeaderText="Bookmark">
    <HeaderTemplate>
    </HeaderTemplate>
    <ItemTemplate>
    </ItemTemplate>
</telerik:GridTemplateColumn>

 

This would solve the problem for Template columns (and all column types that allow you to define HeaderTemplate). This will not work for GridBoundColumn for example as this type doesn’t have HeaderTemplate.

 

Hope this helps someone out there …

1 comment:

Unknown said...

Found good column choosser
Column Chooser


Project Description
WPF Datagrid currently dosent have column chooser.
In this column chooser you can even drag and drop the column to move its position on the grid.
You can even update header value on the fly just by double clicking on it.




Features include:

Column chooser with checkbox to make column visible and invisible.
Select All checkbox is added.
You can drag and drop a row from column chooser to move column in the main grid.
By double clicking on any cell of column chooser you can edit the column header values.
Column Chooser tool is deveoped in C# Visual Studio 2010 . You can even download the application via click once installation method.