We are having an issue with the CellStyleSelector randomly changing the style when scrolling left and right in the GridView.
We have it narrowed down to our comparison in the StyleSelector code. We need to compare the cell value to the Min and Max columns to see if it is within the range. If it is, set the style to Valid, if not set it to Invalid.
This works on loading of the grid, but the scrolling causes it to glitch.
Code where the value of comparison (cell) changes and causes glitch:
public
class
ValidationStyle : StyleSelector
{
public
override
Style SelectStyle(
object
item, DependencyObject container)
{
if
(item
is
ExpandoObject)
{
var inspection = (IDictionary<
string
,
object
>)item;
var cell = container.GetValue(GridViewCell.ValueProperty);
if
(!(cell ==
null
|| cell.ToString() ==
""
))
{
double
.TryParse(cell.ToString(),
out
double
cellValue);
inspection.TryGetValue(
"Max"
,
out
object
maxValue);
inspection.TryGetValue(
"Min"
,
out
object
minValue);
if
((
double
)minValue <= cellValue && cellValue <= (
double
)maxValue)
{
return
Valid;
}
else
{
return
Invalid;
}
}
}
return
null
;
}
public
Style Valid {
get
;
set
; }
public
Style Invalid {
get
;
set
; }
}
Code example using a fixed value of comparison (cell) and does not glitch:
public
class
ValidationStyle : StyleSelector
{
public
override
Style SelectStyle(
object
item, DependencyObject container)
{
if
(item
is
ExpandoObject)
{
var inspection = (IDictionary<
string
,
object
>)item;
int
? cell = 1;
if
(!(cell ==
null
|| cell.ToString() ==
""
))
{
double
.TryParse(cell.ToString(),
out
double
cellValue);
inspection.TryGetValue(
"Max"
,
out
object
maxValue);
inspection.TryGetValue(
"Min"
,
out
object
minValue);
if
((
double
)minValue <= cellValue && cellValue <= (
double
)maxValue)
{
return
Valid;
}
else
{
return
Invalid;
}
}
}
return
null
;
}
public
Style Valid {
get
;
set
; }
public
Style Invalid {
get
;
set
; }
}
We have poured over these forums and every example for StyleSelector uses a fixed value for comparison.
We have applied this concept to the NegativeStyleSelector.zip in this forum and it also glitches: https://www.telerik.com/forums/apply-cellstyleselector-in-code-behind
Any help would be appreciated!
Thanks!