Hi,
I'm trying to set the HeaderStyle in codebehind based on a check of the datarow.
I do this in the CellControlAttached event:
if (e.Cell.Column.Tag != null) { currentYear = (DateTime)e.Cell.Column.Tag; DateTime checkDate = currentYear.AddDays(-7); if (currentYear.Year != checkDate.Year) { e.Cell.Column.HeaderStyle = this.Resources["NewYear"] as Style; }}
The style is defined as followed:
xmlns:igGridDet="clr-namespace:Infragistics.Silverlight.Controls.Primitives;assembly=Infragistics.Silverlight.XamWebGrid.v9.2"
<Style x:Key="NewYear" TargetType="igGridDet:HeaderCellControl"> <Setter Property="Background" Value="Yellow"></Setter> </Style>
However, when I run this code I get: Object reference not set to an instance of an object
So, modifying the HeaderStyle of a Column, is causing the Grid, to basically interrupt it's current layout phase, and restart, however, b/c its never finished, it winds up causing the exceptions you're seeing.
I'm pretty sure, CellControlAttached, isn't the event you should be using anyways. As it only fires for data that is in view. The event was only meant for modifying the style of the cell that's being passed in. And if you're modifying the HeaderStyle of a column based on your data, then you're only going to be invalidating on a subset of your data.
Instead, you should have some sort of logic that actually loops through your data, to determine the styles for a column.
-SteveZ