How to access the values of the cells of calculated columns in RadGridView

Go To StackoverFlow.com

0

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)
2012-04-05 19:26
by Carlos Blanco


2

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.

2012-04-05 20:57
by KRichardson
It's not working for me. It might be the way the bind is done - Carlos Blanco 2012-04-06 13:37
I declared mine as: - using a table from my existing database (int, double - KRichardson 2012-04-06 13:42
Mine are added by code after the user selects to add a new calculated column from a drop down menu. The grid is bound to a collections of items that we get from the DB. I try item['CalcColName'] it return null. item only contains the members that our class for the data has - Carlos Blanco 2012-04-06 13:45
Can you paste your code that is adding the new calculated column - KRichardson 2012-04-06 14:15
I added it. The variables that are there basically are just strings - Carlos Blanco 2012-04-06 17:47
see above edits. I was able to retrieve the data in my WPF application used. You might want to tag your question as WPF or Silverlight - KRichardson 2012-04-06 19:05
Ads