Need help with RadGridView.RowStyle and using a converter

3 posts, 1 answers
  1. kilhoffer
    kilhoffer avatar
    40 posts
    Member since:
    May 2007

    Posted 18 Dec 2012 Link to this post

    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:

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

    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. Answer
    Maya avatar
    4062 posts

    Posted 19 Dec 2012 Link to this post

    Hi Anthony,

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

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. kilhoffer
    kilhoffer avatar
    40 posts
    Member since:
    May 2007

    Posted 19 Dec 2012 Link to this post

    Works perfectly. Thank you!
Back to Top