This is a migrated thread and some comments may be shown as answers.

Iterate all cells on radGrid1_OnInfrastructureExporting

1 Answer 11 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Julian
Top achievements
Rank 1
Julian asked on 11 May 2015, 05:11 PM

I have the following code in the " radGrid1_OnInfrastructureExporting" method:

 

foreach (Cell cell in e.ExportStructure.Tables[0].Columns[1].Cells)
               {
                   var count = 0.00;
                   count++;
 
                   var numStyles = NumberStyles.AllowParentheses | NumberStyles.AllowThousands |
                                   NumberStyles.AllowDecimalPoint;
                   var cellValue = string.Empty;
 
                   cellValue = cell.Text;
 
                   cellValue = cellValue.Replace("<b>", "").Replace("</b>", "").Replace("--", "").Replace(" ", "");
                   cell.Value = cellValue;
 
                   var outCellValue = 0.00;
                   var isNumeric = double.TryParse("cellValue", out outCellValue);
                   var isEmptyOrNull = string.IsNullOrEmpty(cellValue);
 
                   var isText = !isNumeric && !string.IsNullOrEmpty(cellValue) ? true : false;
 
 
                   //if (cellValue.Length >0 && !)
                   if (!isText && !isEmptyOrNull)
                   {
                       cellValue = Double.Parse(cellValue, numStyles).ToString();
                       cell.Value = GetLocalizedValueForExcelExport(Convert.ToDouble(cellValue));
                   }
               }

 

Now I know i have columns[1].Cells so i'm only touching one column but for the life of me I cannot seem to get at all the columns in the grid?

If I type the following into a watch at run time I get:

e.ExportStructure.Tables[0].Columns.Count = 1

So this should be a simple fix. How can I iterate all columns.

Every way that I have tried to get access to all columns in the OnInfrastructureExporting has failed?

 

thanks


1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 14 May 2015, 10:57 AM
Hello Julian,

For optimization purposes, the Columns collection will be initially empty and a column will be created the first time when you try to access it by index. 

For getting the number of column currently rendered in the grid you can use the MasterTableView's RenderColumns collection (just keep in mind that there will be two additional columns at the beginning of the collection).

On a side note, if you need to implement common logic for the cells in all columns, you can use the e.ExportStructure.Tables[0].Cells collection.

Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Julian
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or