Carlos Blanco
Carlos Blanco

Reputation: 8762

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

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)

Upvotes: 0

Views: 1158

Answers (1)

KRichardson
KRichardson

Reputation: 1010

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.

Upvotes: 2

Related Questions