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
295
Create a dynamic UltraGrid then export to Excel from it
posted

I need to export some data to Excel 97/2003 format.  We use Infragistics controls extensively in our applications so I wanted to use the built-in functionality of the Ultragrid to write my Excel file.

I am referencing the Infragistics2.Win.***.v9.2 assemblies in this application.

The class that will be creating the Excel file is a Class Library ( .dll ) project not a WinForms project.

I am creating an instance of the UltraGrid dynamically, then attempting to bind a list of our custom object to it and write the resulting grid to Excel.  The Excel file always comes out empty.  When I step through the debugger, I look at the datasource of the grid after I set the datasource and it looks fine, but if I look at the Rows property, the count is 0.  I've tried forcing an Update() and a Refresh() on the grid after setting the datasource and that doesn't help.  I'll paste in sample code to show you exactly what I'm doing.  I've switched away from our custom object to a test object for simplicity and it still exhibits the same behavior.

This is the method I'm using to create the Excel file.  The "AddressExportObject" is a test class that just has 3 string properties.

So, the final question: Why are there no rows in my grid after I set the datasource?

Thanks,

-BEP

 

private string SaveExcelDoc()
{
	UltraGrid grdAddresses = new UltraGrid();
	UltraGridExcelExporter oExcelExporter = new UltraGridExcelExporter();

	string sFilename = @"C:\TestOutFile.xls";

	BindingList lstAddresses = new BindingList();

	lstAddresses.Add(new AddressExportObject("Cust1", "101 Main St", "Suite 2"));
	lstAddresses.Add(new AddressExportObject("Cust2", "300 Park Way", ""));

	grdAddresses.DataSource = lstAddresses;
	grdAddresses.DataBind();

	oExcelExporter.Export(grdAddresses, sFilename, Infragistics.Excel.WorkbookFormat.Excel97To2003);

	return (sFilename);
}

 

Parents Reply Children