hello,
I am using Infragistics wingrid and c#.I am using the Excel Export Functionality to create a .xlsx file.We have written some code for formatting the exported columns from the grid but we are getting unexpected errors as Unable to merge or the columns are exported in wrong arrangement like :
we have one main grid and several child grids , we want the columns of parent grid to be displayed first then the columns of child grid should be displayed but the columns are displayed in a manner like 1st 2 columns of parent are added then 1 of child etc.
Can you please help us , i have registered version of ingragistics.
Thanks & Regards,
Seema Sharma
Hello Seema,
I`m not sure that I understand well your scenario, but I try to reproduce it in a small sample. Could you please take a look at the attached sample and if you think that I didn`t reproduce your issue, feel free to modify this sample and revert it back to me. I`ll be glad to research it for you.
Let me know if you have any questions.
Regards
this is the sample
hi,
I am using infragistics wingrid version 11.2.
I have added a column temp to which i associated tag as
bandMilestone.Columns["L_TEMP_CS"].Tag="TEMP_COL";
then i called the added a deligate to the wingrid as
uiMain.UgeMain.HeaderCellExported +=new HeaderCellExportedEventHandler(this.UgeMain_HeaderCellExported);
and added the function which will be called as :
private void UgeMain_HeaderCellExported(object sender, HeaderCellExportedEventArgs e)
{
if(e.CurrentWorksheet.Name == CNameMilestoneWS) milExpCtrl.HeaderCellExported(e);
else if(e.CurrentWorksheet.Name == CNameRFCWS) rfcExpCtrl.HeaderCellExported(e);
else if(e.CurrentWorksheet.Name == CNameMscnWS) mscnExpCtrl.HeaderCellExported(e);
else if(e.CurrentWorksheet.Name == CNameOutstandingPointWS) outstandingPointExpCtrl.HeaderCellExported(e);
}
below is the headecellExported function which is called by passing e object to it.
public void HeaderCellExported(HeaderCellExportedEventArgs e)
string msn;
if (e.GridHeader.Column.Tag != null) {
if (e.GridHeader.Column.Tag.Equals("TEMP_COL")) { msn = e.GridHeader.Column.Tag.ToString(); e.CurrentWorksheet.Rows[e.CurrentRowIndex - 1].Cells[e.CurrentColumnIndex].Value = BusProject.GetInstance().GetCurrentProjectName() + "-TEMP MSN"; IWorksheetCellFormat cellFormat = e.CurrentWorksheet.Rows[e.CurrentRowIndex].Cells[e.CurrentColumnIndex].CellFormat; e.CurrentWorksheet.Rows[e.CurrentRowIndex - 1].Cells[e.CurrentColumnIndex].CellFormat.SetFormatting(cellFormat); tempColCount++; if (msn != currentMsn) currentMsn = msn; else if (currentMsn != "" && nbofvisibleTEmpcount == tempColCount) { e.CurrentWorksheet.MergedCellsRegions.Clear ();
WorksheetMergedCellsRegion region = e.CurrentWorksheet.MergedCellsRegions.Add(e.CurrentRowIndex - 1, e.CurrentColumnIndex - (nbofvisibleTEmpcount-1), e.CurrentRowIndex - 1, e.CurrentColumnIndex);
} }
else { msn = e.GridHeader.Column.Tag.ToString(); e.CurrentWorksheet.Rows[e.CurrentRowIndex - 1].Cells[e.CurrentColumnIndex].Value = "MSN " + msn; IWorksheetCellFormat cellFormat = e.CurrentWorksheet.Rows[e.CurrentRowIndex].Cells[e.CurrentColumnIndex].CellFormat; e.CurrentWorksheet.Rows[e.CurrentRowIndex - 1].Cells[e.CurrentColumnIndex].CellFormat.SetFormatting(cellFormat); if (msn != currentMsn) currentMsn = msn; else if (currentMsn != "") { WorksheetMergedCellsRegion region = e.CurrentWorksheet.MergedCellsRegions.Add(e.CurrentRowIndex - 1, e.CurrentColumnIndex - 1, e.CurrentRowIndex - 1, e.CurrentColumnIndex); } } msn_prec = ""; if (firstColumnToMerge == 0) firstColumnToMerge = e.CurrentColumnIndex; if (e.CurrentWorksheet.Rows[e.CurrentRowIndex-1].Cells[e.CurrentColumnIndex-1].Value != null) msn_prec = e.CurrentWorksheet.Rows[e.CurrentRowIndex-1].Cells[e.CurrentColumnIndex-1].Value.ToString(); e.CurrentWorksheet.Rows[e.CurrentRowIndex-1].Cells[e.CurrentColumnIndex].Value = "MSN "+ msn; IWorksheetCellFormat cellFormat = e.CurrentWorksheet.Rows[e.CurrentRowIndex].Cells[e.CurrentColumnIndex].CellFormat; e.CurrentWorksheet.Rows[e.CurrentRowIndex-1].Cells[e.CurrentColumnIndex].CellFormat.SetFormatting(cellFormat) ; if (e.GridHeader.Column.Key.EndsWith("RevAchDates")) { WorksheetMergedCellsRegion region = e.CurrentWorksheet.MergedCellsRegions.Add(e.CurrentRowIndex-1,firstColumnToMerge, e.CurrentRowIndex-1,e.CurrentColumnIndex); firstColumnToMerge = 0; }*/ } if (e.CurrentColumnIndex > lastMilestoneColumn) lastMilestoneColumn = e.CurrentColumnIndex; if (e.GridRow.Band.Key == BusMilestonesDates.CNameMonitoredMilestones) { nbColumnsMilestones = e.CurrentColumnIndex; } else if (e.GridRow.Band.Key == BusMilestonesDates.CNameRelMilestonesLinks) { nbColumnsLink = e.CurrentColumnIndex; }
if (e.GridHeader.Caption == "Responsible") { if (e.GridHeader.Band.Key == BusMilestonesDates.CNameMonitoredMilestones) { e.CurrentWorksheet.Rows[e.CurrentRowIndex].Cells[e.CurrentColumnIndex].Value = "Responsible"; } }
But i dont understand this code was working fine in infragistics version 2003.7
is throwing null reference error in infragistics 11.2.
Actually the object e doenst hold the column value for the column property when passed in the delegate in version 11.2 where as in prior version it worked well.
Please help me in this as i am stuck.Can we have a call anything would do.
Thanks and Regards,
Could you please tell me the exact place in your source code, where is throwing null reference exception ?
My guess is that Column is null. So you should check to make sure e.GridHeader.Column is not Nothing before you try to access the Tag property.
The column value is null , but it was working fine in prior version without any change in the code (above specified).
I m not getting how to resolve this , can you please help me.
The column is not null when we use the same code for infragistics 2003.7
Seema Sharma.
Hi,
There are other types of headers besides column headers. There's the grid header (which I don't exports, anyway), but there are also Group headers. So you are probably getting into that event for a Group header and so the column is null.
So just check to see if the Column is nothing and then skip your code that tries to access the Tag.
(not e.GridHeader.Column is nothing andalso e.GridHeader.Column.Tag != null)