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

Need help with RadGridView.RowStyle and using a converter

2 Answers 268 Views
GridView
This is a migrated thread and some comments may be shown as answers.
kilhoffer
Top achievements
Rank 1
kilhoffer asked on 18 Dec 2012, 10:02 PM
My scenario is fairly simple: I have a grid bound to a VirtualQueryableCollectionView that is loaded with DataRows. Each DataRow has a column containing an integer value for a color that I need to convert to a SolidColorBrush. I'm specifying the RadGridView.RowStyle and an IValueConverter to achieve the setting of the row background. The problem I'm seeing is that my converter is only called one time with a row that actually contains a DataRow for it's 'Item' property. That single call is for the row just out of view in the grid. None of the visible rows before it contain a DataRow as their GridViewRow.Item.

Here is my style attached to the grid:

<telerik:RadGridView.RowStyle>
                <Style TargetType="telerik:GridViewRow">
                    <Setter Property="Background">
                        <Setter.Value>
                            <Binding RelativeSource="{RelativeSource Self}" Converter="{StaticResource DataGridRowBackgroundConverter}" ></Binding>
                        </Setter.Value>
                    </Setter>
                </Style>
            </telerik:RadGridView.RowStyle>


And here is the converter code. Note the comment on line 4:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var gridViewRow = (GridViewRow)value;
            var dataRow = gridViewRow.Item as DataRow;  // This is only true for a single row in the grid!
            if (dataRow == null) return new SolidColorBrush(Colors.Transparent);

            var integerValue = dataRow.Field<int>(DataSourceConstants.ColorColumnName);
            if (integerValue == 0)
            {
                return new SolidColorBrush(Colors.Transparent);
            }

            var bytes = BitConverter.GetBytes(integerValue);
            var color = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);

            return new SolidColorBrush(color);
        }



What could I be doing wrong here?

2 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 19 Dec 2012, 07:00 AM
Hi Anthony,

You can try working with RowStyleSelector instead. Check out our documentation and demos for a reference.  

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
kilhoffer
Top achievements
Rank 1
answered on 19 Dec 2012, 11:26 PM
Works perfectly. Thank you!
Tags
GridView
Asked by
kilhoffer
Top achievements
Rank 1
Answers by
Maya
Telerik team
kilhoffer
Top achievements
Rank 1
Share this question
or