Hi,
Does anyone see any problems with the following code?
Dim exporter As UltraGridExcelExporter = New UltraGridExcelExporter()
Dim tempGrid As UltraGrid = New UltraGrid()
tempGrid.DataSource = dataTable
tempGrid.DataBind()
exporter.Export(tempGrid, fileName)
My dataTable has rows and is correctly configured. The issue is that all I get after the export is an empty file. The DataBind call has no affect.
Thank you,
Rick
Rick,I have seen one major issue with your code that grid is not added as Control on Form, that is why you are not getting any rows in exported excel file, what you need to do is just use the following code to add Grid on Form as control: Me.Controls.Add(tempGrid)and it will work for you i.e. excel will contain rows from datatable.Thank you.Bunty :)
That worked. Thank you!
FYI - the reason you need to add the grid to the form is that, when the grid is not on a form, it has no BindingContext, so it can't get the data from the data source.
So another way to fix the issue would be to assign the grid.BindingContext to the form.BindingContext.
Adding the control to the form is probably better, though. Since it has added benefit that the form's Dispose method will dispose of the controls on that form.