Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1725
How to use the UltraGridDocumentExporter
posted

I'm trying to generate a report that contains a grid and need a bit of help getting it to work.

 The code takes a business object, builds and populates an UltraGrid, creates an exporter and then exports the grid to the report. Here is the core of that

 //* The section has been added and page orientation set to landscape before I get here

IText txt;

txt = section.AddText();
txt.AddContent("Tastables", h1Style);
txt.Heading = Infragistics.Documents.Report.TextHeading.H1;
txt.Margins.Bottom = 10;

UltraGrid grid = new UltraGrid();
Infragistics.Win.AppearanceData appearanceData;
if (Global.GetAppearanceDataFromControl(grid.ComponentRole, "GridColumnHeader", out appearanceData))
{
                    grid.DisplayLayout.CaptionAppearance.BackColor = appearanceData.BackColor;
                    grid.DisplayLayout.CaptionAppearance.BackColor2 = appearanceData.BackColor2;
                    grid.DisplayLayout.CaptionAppearance.ForeColor = appearanceData.ForeColor;
                    grid.DisplayLayout.CaptionAppearance.BackGradientStyle = appearanceData.BackGradientStyle;
}

UltraDataSource ds = _tasting.Tastables().CreateDataSource(); //*This creates the proper data source              
BindingSource tastablesBindingSource = new BindingSource();
tastablesBindingSource.DataSource = ds;
grid.SetDataBinding(tastablesBindingSource, null, true);               

foreach (Tastable tastable in _tasting.Tastables())
{
     tastable.LoadDataSource(ds); //* This adds a row to the 2 bands defined in the DS, one for each item in the list
}
UltraGridDocumentExporter tableExporter = new UltraGridDocumentExporter();
tableExporter.BeginExport += new EventHandler<Infragistics.Win.UltraWinGrid.DocumentExport.BeginExportEventArgs>(tableExporter_BeginExport);

tableExporter.EndExport += new EventHandler<Infragistics.Win.UltraWinGrid.DocumentExport.EndExportEventArgs>(tableExporter_EndExport);

if (null != grid)
    tableExporter.Export(grid, report); //* Build the summary grid only

tableExporter.RowExporting += new EventHandler<Infragistics.Win.UltraWinGrid.DocumentExport.RowExportingEventArgs>(tableExporter_RowExporting);

tableExporter.BeginExport -= new EventHandler<Infragistics.Win.UltraWinGrid.DocumentExport.BeginExportEventArgs>(tableExporter_BeginExport);
                tableExporter.EndExport -= new EventHandler<Infragistics.Win.UltraWinGrid.DocumentExport.EndExportEventArgs>(tableExporter_EndExport);
grid.Dispose();
tableExporter.Dispose();
 

 

The above code does not generate any errors or exceptions and if I look at the datasource it has the proper number of rows, however no output is generated and if I look at what I get in the BeginExport  event, the rows count is 0 so I'm obviously missing something.

I looked at the sample and that didn't seem to do more than what I had except that  I created all this at print time vs design time.

Any help would be appreciated or if there are pointers someplace to more examples on using the Document component in general that would be appreciated as well. 

An update to my question and a comment:

So, It looks like the problem is that nothing actually gets populated in the grid unless/until it is shown. If I create a window and then stuff a grid in it and do the rest of my example I can get something.  The exporter does not actually do what I need to have it do as it does not seem to carry any section header/footer information along.

What I'm trying to do is put the grid in a report that has a header and footer on each section and page numbers. It appears as though the grid is always put within a new section (I'm sure there is some good reason for this) so I'm going back to hand crafting a grid instead of using the exporter as it is more trouble than it appears to be worth.

Neil 

  • 469350
    Verified Answer
    Offline posted

    Hi Neil,

        My guess is that the grid has no BindingContext, since you are never adding it to any container. Try adding the grid to the Form's Control's collection. Or just set the grid.BindingContext to a new BindingContext object.