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

[Solved] Group headers

4 Answers 144 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.
Patrik
Top achievements
Rank 1
Patrik asked on 15 Oct 2010, 12:08 PM
Hello Telerik, I have a question regarding group headers on gridviews.

As illustrated by my screenshot, the group header is the DataFormatString of my grouped column. How can I make it displaying formatted data instead? The column is the data type DateTime? (nullable datetime), and I suspect that's the reason why, but I must have it in nullable format for it to work in other controls. Can I somehow handle how the group header is created?

regards,
Patrik Edberg

4 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 15 Oct 2010, 02:51 PM
Hi Patrik,

Please paste me the code or XAML you use to set the format string so I can check what may have gone wrong.

Best wishes,
Pavel Pavlov
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
Patrik
Top achievements
Rank 1
answered on 18 Oct 2010, 07:12 AM
Hello, the gridview is declared like this:
<telerik:RadGridView                   
                        AutoGenerateColumns="True"
                        BorderThickness="0"                       
                        ShowGroupPanel="False"
                        RowIndicatorVisibility="Collapsed"                                               
                        CanUserInsertRows="False"
                        CanUserDeleteRows="False"
                        CanUserSortColumns="True"
                        IsFilteringAllowed="True"
                        ItemsSource="{Binding Items}"           
                        SelectedItem="{Binding SelectedItem, Mode=OneWay}"
                        SelectionChanged="RadGridView_SelectionChanged"                 
                        AutoGeneratingColumn="RadGridView_AutoGeneratingColumn"
                        RowActivated="RadGridView_RowActivated"
                        />

And in the RadGridView_AutoGeneratingColumn method, I do the following:
private void RadGridView_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
    PropertyInfo property = typeof(ProductsGridItem).GetProperty(e.Column.UniqueName);
    if (property == null)
    {
        e.Cancel = true;
        return;
    }
 
    GridViewDataColumn column = e.Column as GridViewDataColumn;
     
    if (property.PropertyType == typeof(DateTime?) || property.PropertyType == typeof(DateTime))
    {
        column.DataFormatString = "yyyy-MM-dd ddd";
    }
}

Please note that I have removed irrelevant code from this method for sake of clarity. Actually I'm reading the format string from attributes set on properties on the class ProductsGridItem.
0
Accepted
Pavel Pavlov
Telerik team
answered on 20 Oct 2010, 12:47 PM
Hello Patrik,

Please try setting the format string as follows:
DataFormatString=@"{0:yyyy-MM-dd ddd}"

This should fix the problem .

It seems we have some "smart" logic that adds the missing to the format symbols for the cells. That is why the cells manage to show the date.  We are going to include this logic to the group headers as well.

Greetings,
Pavel Pavlov
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
Patrik
Top achievements
Rank 1
answered on 20 Oct 2010, 12:56 PM
Thanks for the answer. It worked!

/P
Tags
GridView
Asked by
Patrik
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Patrik
Top achievements
Rank 1
Share this question
or