Is there a way to get the values for calculated columns in RadGridView?
I have a part in my code where I iterated through all the items that are shown in a RadGridView. The values for calculated columns are not there. I wonder how I can get them.
Right now I'm iterating the collection of items that the grid is bound to. I'm using GridViewExpressionColumn to add this calculated columns to the grid.
EDIT:
GridViewColumn column = new GridViewExpressionColumn
{
UniqueName = columnViewModel.LayoutColumnId.ToString(),
Name = name,
Expression = expression,
IsReadOnly = isReadOnly,
ToolTipTemplate = CreateTooltip(columnViewModel.FormulaText),
IsSortable = false,
IsFilterable = false
};
grid.Columns.Add(column)
First, ensure each column is named with a UniqueName.
Then when iterating through through each of the grids items you can access the text using the code: (FOR ASP.NET AJAX)
foreach (GridDataItem DataItem in grid1.Items)
{
var CalculatedColumnText = DataItem["CalculatedColumn"].Text;
}
(FOR WPF/SILVERLIGHT) - from Telerik Forums
var col = GridView1.Columns["CalculatedColumn"] as GridViewExpressionColumn;
foreach (var GridItem in GridView1.Items)
{
var cellValue = col.GetValueForItem(GridItem);
}
You can convert the text to whichever datatype you need.
Edit: I assumed at first it was ASP.NET rather than WPF/Silverlight. I left both answers in.
item['CalcColName']
it return null. item
only contains the members that our class for the data has - Carlos Blanco 2012-04-06 13:45