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

CellLoaded event question

8 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 23 Nov 2010, 06:59 PM
In an in-browser application, I'm trying to change the foreground color of cells whose text starts with a "!" in the code-behind as shown here:

radGridView1.CellLoaded += (s, f) =>
{
    if (f.Cell.GetType() != typeof(GridViewCell)) return;
    GridViewCell cur = (GridViewCell)f.Cell;
    if (cur.Value == null) return;
    if (cur.Value.ToString().Length == 0) return;
    if (cur.Value.ToString()[0] == '!')
    {
        cur.Foreground = new SolidColorBrush(Colors.Gray);
    }
};

I adapted the datatable object described here (located in the data.cs file) as the grid's itemssource.

For some reason, random cells are have their color changed as I scroll up and down through the table (the data stays correct, however).  Sometimes they are cells that contain exclamation marks, other times they are not.  Cells that were black when I passed by them scrolling down are suddenly gray as I scroll past them going up and vice versa. 

I'm using the current version of the library (downloaded last week).  Any ideas?

Jeff

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 24 Nov 2010, 07:43 AM
Hi,

 This blog post is some kind of old copy of my own blog. You can get the latest version of the DataTable from here. Why not use our style or template selectors to achieve your goal in your case?

Greetings,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Jeff
Top achievements
Rank 1
answered on 24 Nov 2010, 10:31 PM

Thanks for the updated link and my apologies for not spending more time looking through the Telerik blogs first. 

As for the styling, I'm trying to do this in the code-behind because I only want to apply the colors to particular cells (not the first row nor the first or second columns, for example).  I couldn't find anything in the documentation showing how best to apply styles to specific cells in the code-behind.  However, when I tried what you described in your Feb 3, 2009 blog entry, it had the same problem as before - applying the gray foreground to random cells which change as I scroll up and down through the grid.  I made a sample project including your datatable and a default datagrid in the XAML that demonstrates the problem I'm having:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.GridView;
using Telerik.Data;
using Telerik.Windows;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;
  
namespace GrayGrid
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            Loaded += new RoutedEventHandler(MainPage_Loaded);
            InitializeComponent();
        }
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn() { ColumnName = "C0", DataType = typeof(string) });
            dt.Columns.Add(new DataColumn() { ColumnName = "C1", DataType = typeof(string) });
            dt.Columns.Add(new DataColumn() { ColumnName = "C2", DataType = typeof(string) });
  
            DataRow row = null;
  
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "!xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
  
            radGridView1.Loaded += (s, f) =>
            {
                var cell = radGridView1.ChildrenOfType<GridViewCell>().Where(cur => cur.Value != null && cur.Value.ToString().Length > 0 && cur.Value.ToString()[0] == '!').ToList();
                cell.ForEach(cur => cur.Foreground = new SolidColorBrush(Colors.Gray));
            };
            radGridView1.ItemsSource = dt;
        }
    }
}

Can you take a look and let me know what direction I should take on this?  Thanks!

Jeff
0
Yavor Georgiev
Telerik team
answered on 25 Nov 2010, 01:08 PM
Hi Jeffrey,

 RadGridView reuses UI elements such as GridViewCell and GridViewRow in order to lower memory and improve performance. That is why when you set properties of GridViewCell for specific items you can sometimes see those cells being reused to display other items.

 I think that the correct solution would be to use CellStyle Selectors, as Vlad suggested.

Greetings,
Yavor Georgiev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Jeff
Top achievements
Rank 1
answered on 27 Nov 2010, 03:22 AM
I was sort of able to do what you suggested by adapting the CellStyleSelector solution that Maya demonstrated here, but it appears to have the same problem.  Below is my code, modified to use CellStyleSelector.  Note that I edited the ConditionalStyleSelector class to pass the GridViewCell object to the converter function, which may be the source of the problem.  It appeared that I had to do it this way because the item object sent to the CellStyleSelector is the entire row, not the cell being tested, so I had no idea which column to check vs. the exclamation point. 

When I tell it to test a particular cell in the item, that is, pass the entire row item and tell it to check a particular one of them, it appears to work correctly, but this is impractical because there will be an arbitrary number of columns in the report and I can't provide a separate CellStyleSelector function for each of them. 

Anyway, here's the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.GridView;
using Telerik.Data;
using Telerik.Windows;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;
using System.Windows.Data;
  
namespace GrayGrid
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            Loaded += new RoutedEventHandler(MainPage_Loaded);
            InitializeComponent();
        }
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn() { ColumnName = "C0", DataType = typeof(string) });
            dt.Columns.Add(new DataColumn() { ColumnName = "C1", DataType = typeof(string) });
            dt.Columns.Add(new DataColumn() { ColumnName = "C2", DataType = typeof(string) });
  
            DataRow row = null;
  
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
  
            radGridView1.ItemsSource = dt;
  
            radGridView1.Loaded += (s, f) =>
                {
                    for (int col = 0; col < radGridView1.Columns.Count; col++)
                    {
                        Style negativeStyle = new Style();
                        negativeStyle.TargetType = typeof(GridViewCell);
                        Setter backGroundSetter = new Setter();
                        backGroundSetter.Property = GridViewCell.ForegroundProperty;
                        backGroundSetter.Value = new SolidColorBrush(Colors.Gray);
                        negativeStyle.Setters.Add(backGroundSetter);
  
                        // Positive Style
                        Style normalStyle = new Style();
                        normalStyle.TargetType = typeof(GridViewCell);
  
                        //Selector and Rules
                        ConditionalStyleSelector selector = new ConditionalStyleSelector();
                        ConditionalStyleRule negativeRule = new ConditionalStyleRule();
                        negativeRule.Style = negativeStyle;
                        negativeRule.Value = false;
                        ConditionalStyleRule normalRule = new ConditionalStyleRule();
                        normalRule.Style = normalStyle;
                        normalRule.Value = true;
  
                        selector.Rules.Add(negativeRule);
                        selector.Rules.Add(normalRule);
                        ExclamationValueConverter converter = new ExclamationValueConverter();
                        selector.ConditionConverter = converter;
                        radGridView1.Columns[col].CellStyleSelector = selector;
                    }
                };
        }
    }
  
    public class ExclamationValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string converterValue = (string)((GridViewCell)value).Value;

  

            if (converterValue != null)
            {
                return converterValue[0] == '!' ? false : true;
            }
  
            return null;
        }
  
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
  
    public class ConditionalStyleSelector : StyleSelector
    {
        public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
        {
            object conditionValue = this.ConditionConverter.Convert(container, null, null, null);
            foreach (ConditionalStyleRule rule in this.Rules)
            {
                if (Equals(rule.Value, conditionValue))
                {
                    return rule.Style;
                }
            }
            return base.SelectStyle(item, container);
        }
  
        List<ConditionalStyleRule> _Rules;
        public List<ConditionalStyleRule> Rules
        {
            get
            {
                if (this._Rules == null)
                {
                    this._Rules = new List<ConditionalStyleRule>();
                }
  
                return this._Rules;
            }
        }
  
        IValueConverter _ConditionConverter;
        public IValueConverter ConditionConverter
        {
            get
            {
                return this._ConditionConverter;
            }
            set
            {
                this._ConditionConverter = value;
            }
        }
    }
  
    public class ConditionalStyleRule
    {
        object _Value;
        public object Value
        {
            get
            {
                return this._Value;
            }
            set
            {
                this._Value = value;
            }
        }
  
        Style _Style;
        public Style Style
        {
            get
            {
                return this._Style;
            }
            set
            {
                this._Style = value;
            }
        }
    }
}

Any suggestions about how I can modify this?

Jeff
0
Jeff
Top achievements
Rank 1
answered on 28 Nov 2010, 01:07 AM
Disregard my previous post, as I stand corrected:  the original problem persists even after switching over to using the cellstyleselector.  It is still randomly graying cells whether I test the row item member or the gridview cell.  I've simplified the code I sent previously as shown below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.GridView;
using Telerik.Data;
using Telerik.Windows;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;
using System.Windows.Data;
  
namespace GrayGrid
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            Loaded += new RoutedEventHandler(MainPage_Loaded);
            InitializeComponent();
        }
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            radGridView1.AutoGenerateColumns = true;
  
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn() { ColumnName = "C0", DataType = typeof(string) });
            dt.Columns.Add(new DataColumn() { ColumnName = "C1", DataType = typeof(string) });
            dt.Columns.Add(new DataColumn() { ColumnName = "C2", DataType = typeof(string) });
  
            DataRow row = null;
  
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "!xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow();  row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx";  dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "!xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
            row = dt.NewRow(); row["C0"] = "xx"; row["C1"] = "xx"; row["C2"] = "xx"; dt.Rows.Add(row);
  
            radGridView1.ItemsSource = dt;
  
            radGridView1.Loaded += (s, f) =>
                {
                    for (int col = 0; col < radGridView1.Columns.Count; col++)
                    {
                        radGridView1.Columns[col].CellStyleSelector = new ConditionalStyleSelector();
                    }
                };
        }
    }
  
    public class ConditionalStyleSelector : StyleSelector
    {
        public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
        {
            if (((string)((GridViewCell)container).Value)[0] == '!')
            //dynamic cur = item;                 //Unremark these to test specific row item member
            //if (((string)(cur.C0))[0] == '!')   //
            {
                Style gray = new Style();
                gray.Setters.Add(new Setter(GridViewCell.ForegroundProperty, new SolidColorBrush(Colors.Gray)));
                gray.TargetType = typeof(GridViewCell);
                return gray;
            }
            else
            {
                Style black = new Style();
                black.Setters.Add(new Setter(GridViewCell.ForegroundProperty, new SolidColorBrush(Colors.Black)));
                black.TargetType = typeof(GridViewCell);
                return black;
            }
        }
    }
}

Can you help me to see what I'm missing?  Thanks!

Jeff
0
Yavor Georgiev
Telerik team
answered on 29 Nov 2010, 03:12 PM
Hello Jeffrey,

 I'm sorry, but I'm unable to reconstruct your applications from the fragments you have provided and the DataTable class in the blog post you linked to. Could you please open a separate support ticket and attach your application there?

Best wishes,
Yavor Georgiev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Sanjay
Top achievements
Rank 2
answered on 05 Jan 2015, 07:30 PM
I am also running into this same problem in production. Did you guys find out the resolution of this issue ?

Thanks!
0
Dimitrina
Telerik team
answered on 07 Jan 2015, 10:28 AM
Hello,

Do you eventually rely on the visual elements (i.e. GridViewCell, GridViewRow)? Generally, we do not recommend working with them as RadGridView is a virtualized control and its elements are reused as they are brought in and out the view area. You can also check our online documentation explaining how the UI virtualization works. 

I would suggest you to implement your logic based on the bound data item instead.


Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Jeff
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Jeff
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Sanjay
Top achievements
Rank 2
Dimitrina
Telerik team
Share this question
or