I am trying to get certain rows to format as a percent while the default formatting is currency. We are using Infragistics NetAdvantage 2006 Volume 2 CLR 2.0 and .Net 2.0. Below is the code I have tried (including a commented out attempt.
protected void UltraWebGridExcelExporter1_EndExport(object sender, Infragistics.WebUI.UltraWebGrid.ExcelExport.EndExportEventArgs e){ for (int j = 1; j < 7; j++) e.CurrentWorksheet.Columns[j].CellFormat.FormatString = CurFormat;
//int rowCount = (e.CurrentWorksheet.Rows as ICollection<Infragistics.Excel.WorksheetRow>).Count; int rowCount = e.CurrentWorksheet.Rows[((ICollection<Infragistics.Excel.WorksheetRow>)e.CurrentWorksheet.Rows).Count - 1].Index + 1; string headerValue;
for (int j = 1; j < rowCount; j++) { headerValue = Convert.ToString( e.CurrentWorksheet.Rows[j].Cells[0].Value);
if (headerValue.Contains("%")) { for (int jj = 1; jj < 7; jj++) e.CurrentWorksheet.Rows[j].Cells[jj].CellFormat.FormatString = PerFormat; } }}
The error I last got is pasted below:
Error Message: Unable to cast object of type 'Infragistics.Excel.WorksheetRowCollection' to type 'System.Collections.Generic.ICollection`1[Infragistics.Excel.WorksheetRowCollection]'.
Any suggestions or help in finding out the solution would be greatly appreciated.
It looks like you are trying to cast the collection to ICollection<WorksheetRowCollection> instead of ICollection<WorksheetRow>. However, the rows collection always has all rows available to it, but they are lazily loaded, so the Count, which just returns the number of lazily loaded items, isn't really what you want here. If you want to iterate all rows which have been created, use a foreach loop.
Just tried a foreach loop, and get the error that Infragistics.Excel.WorksheetRow does not contain a public definition for GetEnumerator. From one of the many posts I have tried looking at before posting, I beleive the ability to do a foreach was only available after a particular version.
That is what I was thinking it should be. I am still getting the error mentioned above though. Below is my version of the foreach (just do to namespace differences)
foreach (Infragistics.Excel.WorksheetRow r in e.CurrentWorksheet.Rows)
Here is the full error:
foreach statement cannot operate on variables of type 'Infragistics.Excel.WorksheetRowCollection' because 'Infragistics.Excel.WorksheetRowCollection' does not contain a public definition for 'GetEnumerator' ...
Thank you for trying to help me by the way. hopefully we can figure something out.
Oh, I think you're right. I believe the collection did not implement ICollection<T> until version 7.2. Unfortunately, if you cannot upgrade to a later version, I don't think there is anything that can be done other than iterating all rows with a for loop.
Ok, but that still leaves me where I started. The two versions of getting the row count (total number of rows) are not working. Any tips to get that working?
Sorry, I meant you can iterate all rows possible (which will lazily create all rows), by always looping from 0 to 65535.
So then with my version there is no way to get a value for the number of rows that actually have data?
Hi MikeHas this issue been sorted yetHow to get the number of actual rows please?
Thanks
Ok. Thank you for the all the help. :)
No, and in fact, even with the current version, the Count does not give you the number of rows with data. As I said before, it returns the number of rows which have already been lazily created. So just accessing a new row will increase the count.