Hello!
I have many expression columns in my grid.
In the RowLoaded-Event I want th check, if the result of the expression is lower than 0. If yes, the text (forecast) color should be set to red.
How can I access the result of the expression?
I tried different things, but I'm not able to get the value for checking.
What I'm doing wrong? Please help.
Kind regards
Michael
I have many expression columns in my grid.
In the RowLoaded-Event I want th check, if the result of the expression is lower than 0. If yes, the text (forecast) color should be set to red.
How can I access the result of the expression?
private
void
gridview1(
object
sender, RowLoadedEventArgs e)
{
var myExpressionCellList = e.Row.ChildrenOfType<GridViewCell>.Where(c => c.Column.UniqueName ==
"eAbwVjKgMon1"
).toList();
foreach
(GridViewCell cell
in
myExpressCellList)
{
cell. .... ?????
}
}
I tried different things, but I'm not able to get the value for checking.
What I'm doing wrong? Please help.
Kind regards
Michael
4 Answers, 1 is accepted
0
Hello Michael,
Didie
the Telerik team
I would recommend you to use a CellStyleSelector to achieve your goal. Based on the data, you can apply the appropriate style.
I hope this is helpful.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Michael
Top achievements
Rank 1
answered on 21 May 2012, 10:08 AM
Hello!
Sorry that I didn't answered before, but we had a long weekend here in Germany.
I tried your suggestions and I think it would work, but I have a special problem.
I try to explain it abstractly:
My datagrid binds to a business objects called "Absatz". There are 12 properties for holding the sales figures for one year on a monthly basis. For every of the 12 GridViewDataColumns I need in addition 4 GridViewExpressionColumns for calculating abberations. If a abberation is negative, the figure should be displayed in red color. So I use the CellStyleSelector-Property for the Expression-Columns.
The item which is commited to the overridden SelectStyle-method is of the type "Absatz". So I would need to calculate the abberations again in the method for each "abberation calumn". But the method only can return one style for one condition.
I tried to detect which expression column calls the SelectStyle by container.ParentOfTypey<GridViewVolumn>().Name or something like that, so the method only calculates the abberation for the right column. But I don't get the right column?
What I'm doing wrong.
Thank you.
Michael
Sorry that I didn't answered before, but we had a long weekend here in Germany.
I tried your suggestions and I think it would work, but I have a special problem.
I try to explain it abstractly:
My datagrid binds to a business objects called "Absatz". There are 12 properties for holding the sales figures for one year on a monthly basis. For every of the 12 GridViewDataColumns I need in addition 4 GridViewExpressionColumns for calculating abberations. If a abberation is negative, the figure should be displayed in red color. So I use the CellStyleSelector-Property for the Expression-Columns.
The item which is commited to the overridden SelectStyle-method is of the type "Absatz". So I would need to calculate the abberations again in the method for each "abberation calumn". But the method only can return one style for one condition.
I tried to detect which expression column calls the SelectStyle by container.ParentOfTypey<GridViewVolumn>().Name or something like that, so the method only calculates the abberation for the right column. But I don't get the right column?
What I'm doing wrong.
Thank you.
Michael
0
Michael
Top achievements
Rank 1
answered on 21 May 2012, 11:09 AM
Hello!
Perhaps there is a better (shorter code) solution, but I managed it now like this:
Perhaps there is a better (shorter code) solution, but I managed it now like this:
public
class
RadGridNumberStyle : Telerik.Windows.Controls.ConditionalStyleSelector
{
public
override
System.Windows.Style SelectStyle(
object
item, System.Windows.DependencyObject container)
{
var theColumn = container
as
GridViewCellBase;
if
(item
is
Absatz)
{
Absatz a = item
as
Absatz;
switch
(theColumn.Column.UniqueName)
{
case
"eAbwVjKgMon1"
:
{
if
((a.decPlanMon1 - a.decVjIstMon1) < 0)
{
return
NegativerWertStyle;
}
else
{
return
PositiverWertStyle;
}
}
case
"eAbwVjPrMon1"
:
{
if
((a.decPlanMon1 - a.decVjIstMon1) < 0)
{
return
NegativerWertStyle;
}
else
{
return
PositiverWertStyle;
}
}
case
"eAbwLjKgMon1"
:
{
if
((a.decPlanMon1 - a.decLjIstMon1) < 0)
{
return
NegativerWertStyle;
}
else
{
return
PositiverWertStyle;
}
}
... and so on!
0
Hi,
Didie
the Telerik team
In case you would like to use the same CellStyleSelector for all the columns, then you will need to manually handle the recognition of the column. You have done that.
Another approach would be to use a different selector for each of the columns.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>