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
410
How Do I specify individual columns for Export?
posted

I'm using the UltraGridExcelExporter to export contents from a DataGridView.  The DataGridView has many columns and I only want certain columns to be exported, for instance "reading_date", "gw_elev_ft" and "gw_depth_ft"

How can I specify this using my existing block of code?:

private void ExportGraphingDataToExcel()

    {

      string sensorName = cbxMonitorList.Value.ToString();

      string startDate = clndrGwMonStart.Value.ToString("yyyyMMdd");

      string endDate = clndrGwMonEnd.Value.ToString("yyyyMMdd");

      string graphingDataExportFilePath = "C:\\temp\\GraphingData" + "_" + sensorName + "_" +   startDate + "-" + endDate + ".xls";

      try

      {

        SetStatus("Exporting monitor graphing data to Excel file...");

        this.ultraGridExcelExporter.Export(this.dgvGwMonGraphData, graphingDataExportFilePath);

        MessageBox.Show("Groundwater monitor graphing data exported to " + graphingDataExportFilePath, "Export Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);

      }

      catch (Exception ex)

      {

        SetStatus("Error encountered...");

        MessageBox.Show("Error running ExportUpdateErrorsToExcel: " + ex.Message, "Export Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

      }

        finally

      {

        SetStatus("Ready");

      }

    }

 

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi,

    I'm a bit confused. The UltraGridExcelExporter only works with the UltraGrid control. It does not work with a DataGridView. So I can only assume that this.dgvGwMonGraphData is an UltraWinGrid and not a DataGridView. Otherwise, this code would not even compile.

    Anyway, what you can do is handle the BeginExport event of the UltraGridExcelExporter. This event passes you a Layout which is a clone of the on-screen grid's layout. Since it's a clone, you can modify the layout and it will affect the export and not the on-screen grid. So you can simply hide the columns you want to hide:

    e.Layout.Bands[0].Columns["my column"].Hidden = true;

Children
  • 410
    Verified Answer
    posted in reply to Mike Saltzman

    Yes you are correct. I simply renamed the UltraGrid and refer to them as "dgv___"

    I used the following code from here: http://sblanco.wordpress.com/category/infragistics-winforms/

    and your code to get the following:

     

    using Infragistics.Win.UltraWinGrid.ExcelExport; 

    ultraGridExcelExporter.BeginExport += delegate(object sender, BeginExportEventArgs e)

            {

              ColumnsCollection columns = e.Layout.Bands[0].Columns;

              columns.Band.Columns["gwmon_edit_id"].Hidden = true;

              columns.Band.Columns["session_edit_id"].Hidden = true;

              columns.Band.Columns["edit_date"].Hidden = true;

              columns.Band.Columns["edited_by"].Hidden = true;

              columns.Band.Columns["sensor_name"].Hidden = true;

              columns.Band.Columns["reading_hertz"].Hidden = true;

              columns.Band.Columns["head_ft"].Hidden = true;

              columns.Band.Columns["head_psi"].Hidden = true;

              columns.Band.Columns["f2_scale"].Hidden = true;

              columns.Band.Columns["ground_elev_ft"].Hidden = true;

              columns.Band.Columns["max_gw_elev_ft"].Hidden = true;

              columns.Band.Columns["min_gw_elev_ft"].Hidden = true;

            };

    this.ultraGridExcelExporter.Export(this.dgvGwMonGraphData, graphingDataExportFilePath);

     

    WORKS PERFECTLY. Thanks a lot!