I want to change the background of RadGridView header row. I also read the link provided http://www.telerik.com/help/silverlight/gridview-styling-header.html, but when I try to do that on my Blend, the steps are not repeated on my Blend.
Can you please suggested how to change the header background?
Also Filter icons are not visible on my RadGridView. Do I have to add some settings for that?
Thanks,
Rashmi
7 Answers, 1 is accepted
If all you want to do is set the background of the header row there is no need to go through all the steps in the tutorial. You can define a style which sets the background and then apply it to the grid via the HeaderRowStyleProperty.
<Style x:Key="GridViewHeaderRowStyle" TargetType="grid:GridViewHeaderRow"> <Setter Property="Background" Value="Red" /> </Style> .... <telerik:RadGridView HeaderRowStyle="{StaticResource GridViewHeaderRowStyle}" />NB: The namespace prefixes might be different in your case.
Greetings,
Kalin Milanov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Sorry for very late reply and thanks for your response. I already tried what you have suggested but still GridView header background remains same.
My code sample is -
<UserControl.Resources>
<Style x:Key="GridViewHeaderRowStyle" TargetType="gridView:GridViewHeaderRow">
<Setter Property="Background" Value="Red" />
</Style>
</UserControl.Resources>
<grid:RadGridView ShowGroupFooters="True" ShowColumnFooters="True" MultipleSelect="True" x:Name="grdExpenseList"
RowIndicatorVisibility="Collapsed" IsReadOnly="False" AutoGenerateColumns="False" ColumnsWidthMode="Fill"
CanUserFreezeColumns="False" HeaderRowStyle="{StaticResource GridViewHeaderRowStyle}" >
.....columns
</grid.RadGridView>
Please do let me know if I am doing anything wrong or I have to change any settings.
Thanks,
Rashmi
You are doing nothing wrong in the sample you have sent me. I think there might have been some misunderstanding about the issue.
What you are doing following my suggestion is indeed changing the background of the header row. However in that row there are header cells which come with their own style and template which you will need to style separately.
Attached I am sending you a sample which has a grid with red header row and two columns the fist of which is not styled while the second one is red.
Does this illustrate the issue you are having?
Greetings,
Kalin Milanov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Hello Kalin,
Thanks for your solution. That solved my mystery. You were right I want to change the Cell background but I thought that will be done by changing entire row background.
I have marked your reply as answer but I want to clear one more thing about the Gridview. We are using WCF service to bind our GridView and I have added code to Sum Total of a column. As the asynchronous call takes time for filling the data, my Total is never displayed as the design is completed for the grid. We then supplied the Total from code behind instead from XAML.
So can you just verify me if that is the only way of doing the same. Also the same is applicable to Filtering. We have to off filtering first and bind the grid and again make filtering on.
Thanks,
Rashmi
Can you post your code? How exactly totals are added in your case?
All the best,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Sorry for being very late. Originally we used following code to display totals.
| <grid:GridViewDataColumn FooterCellStyle="{StaticResource GridViewFooterCellStyle}" HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" Width="90" TextAlignment="Right" UniqueName="ExpenseAmount" IsReadOnly="True" DataFormatString="{}{0:n}" DataMemberBinding="{Binding ExpenseAmount}"> |
| <grid:GridViewDataColumn.AggregateFunctions> |
| <telerikdata:SumFunction Caption="Sum: " ResultFormatString="{}{0:n}" SourceField="ExpenseAmount" /> |
| </grid:GridViewDataColumn.AggregateFunctions> |
| <grid:GridViewDataColumn.Footer> |
| <StackPanel Orientation="Vertical" Margin="5,0"> |
| <gridView:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center" Grid.Column="4"> |
| <ItemsControl.ItemTemplate> |
| <DataTemplate> |
| <StackPanel Orientation="Horizontal" VerticalAlignment="Center"> |
| <TextBlock VerticalAlignment="Center" Text="{Binding Caption}" /> |
| <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}" /> |
| </StackPanel> |
| </DataTemplate> |
| </ItemsControl.ItemTemplate> |
| <ItemsControl.ItemsPanel> |
| <ItemsPanelTemplate> |
| <StackPanel Orientation="Vertical" /> |
| </ItemsPanelTemplate> |
| </ItemsControl.ItemsPanel> |
| </gridView:AggregateResultsList> |
| </StackPanel> |
| </grid:GridViewDataColumn.Footer> |
| </grid:GridViewDataColumn> |
And now we are doing the same from code behind as follows -
| var col = grdExpenseList.Columns["ExpenseAmount"] as GridViewDataColumn; |
| col.TextAlignment = TextAlignment.Right; |
| col.AggregateFunctions.Add(new Telerik.Windows.Data.SumFunction |
| { |
| FunctionName = "DisplayExpenseTotal", |
| ResultFormatString = "{0:n}", |
| SourceField = "ExpenseAmount" |
| }); |
| grdExpenseList.CalculateAggregates(); |
| if (IsAggrgatePresent("DisplayExpenseTotal")) |
| { |
| TextBlock lblTotalAmount = GetTextBlockFromGrid("lblTotalAmount"); |
| lblTotalAmount.Text = currencySymbol + " " + this.grdExpenseList.AggregateResults["DisplayExpenseTotal"].FormattedValue.ToString(); |
| } |
The above code is called after we fill our grid on Main control's loded event.
Please let me know if you need more details of the same.
Regards,
Rashmi
After analyzing the problem I found the following:
We have had bug which prevented totals from being shown if ItemsSource was updated runtime. We have already applied a fix. I have tested a similar scenario and it seems to solve the problem.
The fix will be available to you with the very next ServicePack - coming in less than a week.
After upgrading to the service pack you should be able to have the totals displayed using the ordinary approach - defining the aggregate function initially and setting the ItemsSource later in the service callback - no more need of workarounds.
I am not sure there will be an internal build this Friday , but in case you find it available for download in your Client.Net account at the end of the week , the fix will be included within and you may give it a try.
Please excuse us for the inconvenience caused.
Sincerely yours,
Pavel Pavlov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
