i have created a derived class from telerik:RadGridView. i need to styling the cells based on the data. so that i have created a styling class and use it as cellstyleselector for columns. i need to sett column cell style for each column and i used the below code but it does not work. do you have any idea of why it does not works?
i have created a derived class from telerik:RadGridView. i need to styling the cells based on the data. so that i have created a styling class and use it as cellstyleselector for columns. i need to sett column cell style for each column and i used the below code but it does not work. do you have any idea of why it does not works?
public class WPFGridConv:RadGridView
{
public WPFGridConv()
{
this.ShowGroupPanel = false;
this.Loaded += WPFGridConv_Loaded;
this.AutoGeneratingColumn += WPFGridConv_AutoGeneratingColumn;
this.ValidationType = GridViewValidationType.None;
this.ValidatesOnDataErrors= GridViewValidationMode.InViewMode;
}
private void WPFGridConv_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
CreateHeader();
}
public void WPFGridConv_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
CreateHeader();
}
private void CreateHeader()
{
foreach (Telerik.Windows.Controls.GridViewColumn column in this.Columns)
{
column.CellStyleSelector= new GridStyleSelector();
}
}
}
public class GridStyleSelector : StyleSelector
{
public override Style SelectStyle(object item, DependencyObject container)
{
if (container is GridViewCell)
{
GridViewCell cell = container as GridViewCell;
string columnId = cell.Column.Tag.ToString();
WPFGridConv grid = cell.ParentOfType<
WPFGridConv
>();
List<
InputClass.GridColumnInfoClass
> columnsInfoList = grid.workingGridClass.ListOfColumnsInfo;
InputClass.GridColumnInfoClass columnInfo = columnsInfoList.Find(x => x.id == columnId);
Type columnType = columnInfo.typeOfColumn;
if ((cell.Value==null||string.IsNullOrEmpty(cell.Value.ToString())) && columnInfo.IsValueNecessary)
{
return NeedeValueStyle;
}
else
{
if (columnType == null || columnType == typeof(double))
{
double dummyDbl;
if (!double.TryParse(cell.Value.ToString(), out dummyDbl))
return BadInputStyle;
else
return CorrectValueStyle;
}
else if (columnType == typeof(int))
{
int dummyInt;
if (!int.TryParse(cell.Value.ToString(), out dummyInt))
return BadInputStyle;
else
return CorrectValueStyle;
}
return CorrectValueStyle;
}
}
return null;
}
public Style OutOfRangeStyle
{
get
{
Style returnStyle=new Style(typeof(GridViewCell));
returnStyle.Setters.Add(new Setter(GridViewCell.BorderBrushProperty, new SolidColorBrush(Colors.Purple)));
return returnStyle;
}
set
{
}
}
public Style BadInputStyle {
get
{
Style returnStyle = new Style(typeof(GridViewCell));
returnStyle.Setters.Add(new Setter(GridViewCell.BorderBrushProperty, new SolidColorBrush(Colors.Red)));
return returnStyle;
}
set
{
}
}
public Style NeedeValueStyle
{
get
{
Style returnStyle = new Style(typeof(GridViewCell));
returnStyle.Setters.Add(new Setter(GridViewCell.BorderBrushProperty, new SolidColorBrush(Colors.IndianRed)));
return returnStyle;
}
set
{
}
}
public Style CorrectValueStyle
{
get
{
Style returnStyle = new Style(typeof(GridViewCell));
returnStyle.Setters.Add(new Setter(GridViewCell.BorderBrushProperty, new SolidColorBrush(Colors.Black)));
return returnStyle;
}
set
{
}
}
}