This is a migrated thread and some comments may be shown as answers.
Change HeaderCellStyle from code behind
0 Answers 30 Views
This is a migrated thread and some comments may be shown as answers.
Cookie Monster
Top achievements
Rank 1
Cookie Monster asked on 27 Sep 2011, 02:52 AM
Hi,

I need to change gridview header cell background if any filter was applied to this column.

So, I added 'filtered' event handler and try to change the header cell style:
void mainAlarmGrid_Filtered(object sender, GridViewFilteredEventArgs e)
       {
           if (e.ColumnFilterDescriptor.IsActive)
           {
               ((GridViewDataColumn)e.ColumnFilterDescriptor.Column).HeaderCellStyle = (Style)Application.Current.Resources["GridViewHeaderCellStyleFiltered"];
           }
           else
               MessageBox.Show("unfiltered");
       }

Now, it works fine, but after clicking on the filtering icon on that cell again, I get this exception every time:

Error: Unhandled Error in Silverlight Application Value does not fall within the expected range.   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
   at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
   at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
   at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)
   at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
   at Telerik.Windows.Controls.GridView.FilteringDropDown.OnIsDropDownOpenChanged(Boolean oldValue, Boolean newValue)
   at Telerik.Windows.Controls.GridView.FilteringDropDown.OnIsDropDownOpenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
   at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
   at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
   at Telerik.Windows.Controls.GridView.FilteringDropDown.OnDropDownButtonClick(Object sender, RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Primitives.ToggleButton.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Source: http://localhost:60274/AIC.Web/AIC.Web.Silverlight.AlarmsAppTestPage.aspx

The style is very simple:
<LinearGradientBrush x:Key="GridView_HeaderCellBackground" EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
           <GradientStop Color="#FF828F8E" Offset="1"/>
           <GradientStop Color="#FFB7CAC9"/>
           <GradientStop Color="#FFC4A48E" Offset="0.352"/>
           <GradientStop Color="#FFC68F4B" Offset="0.512"/>
       </LinearGradientBrush>
        
       <Style x:Key="GridViewHeaderCellStyleFiltered" TargetType="telerik:GridViewHeaderCell">
           <Setter Property="Background" Value="{StaticResource GridView_HeaderCellBackground}"/>
           <Setter Property="HorizontalContentAlignment" Value="Stretch"/>        
       </Style>

Maybe you have some ideas on how I can implement that properly ?

Regards

No answers yet. Maybe you can help?

Asked by
Cookie Monster
Top achievements
Rank 1
Share this question
or