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

How do add a text block to the column header?

1 Answer 77 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jerry Kurata
Top achievements
Rank 1
Jerry Kurata asked on 11 Mar 2011, 08:32 PM
Hi,

We are adding a feature that lets users summarize the data in columns containing lists of numbers.  The user can select to show either the unsummarized, maximum, minimum, or average values.  I have the calculations working, but now need to display the column's current summarization mode in the column header. I want to show this mode in a different font size from the rest of the header, and perhaps offset to the left.

I assume the best way to do this would be to add an addition text block to the header template, bind the current summarization value to a string, and then hide and show the text block based on the presence of the string or a visibility property.  However, I am unsure of the exact changes I need to alter the column header and how to wire up any bound properties to the column header.

Can someone provide me some guidance?

Thanks,

Jerry


1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 12 Mar 2011, 01:44 PM
Hello Jerry Kurata,

There are a couple of options. Firstly, you may just update the header by concatenating the desired string. It might be something similar to this one:

this.playersGrid.Columns[0].Header = this.playersGrid.Columns[0].Header + " myState";

Another possibility may be to define the Header like:
<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}">
                    <telerik:GridViewDataColumn.Header>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="Name" />
                            <TextBlock x:Name="myTxtBlock"/>
                        </StackPanel>
                    </telerik:GridViewDataColumn.Header>
                </telerik:GridViewDataColumn>

 
And handle the change of the text like:
private void Button1_Click(object sender, RoutedEventArgs e)
        {
            var panelche = this.playersGrid.Columns[0].Header as StackPanel;
            var txt = panelche.ChildrenOfType<TextBlock>();
            foreach(TextBlock txtBlock in txt)
            {
                if(txtBlock.Name == "myTxtBlock")
                {
                    txtBlock.Text = "myState";
                }              
            }      
        }
 

Kind regards,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Jerry Kurata
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or