We are using an invisible grid to make an export to excell.
The problem is that the export is empty.
Here is the xaml and the code we use.
If we debug, we can see that the itemssource does contain 12 items.
Could this be because we fill up the grid right before we export it? Do we need to do anything else?
<
telerik:RadGridView Visibility="Collapsed" Grid.Row="1" Grid.Column="0" ColumnWidth="*" AutoExpandGroups="True" RowStyleSelector="{StaticResource styleSelector}" AutoGenerateColumns="True" ItemsSource="{Binding}" Margin="0,0,0,0" Name="gridExport" CanUserReorderColumns="False" IsFilteringAllowed="False" IsReadOnly="True" ShowGroupPanel="False">
</telerik:RadGridView>
private
void menuItemClick(object o, Telerik.Windows.RadRoutedEventArgs e)
{
string extension = "xls";
ExportFormat format = ExportFormat.Html;
SaveFileDialog dialog = new SaveFileDialog();
dialog.DefaultExt = extension;
dialog.Filter =
String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excell");
dialog.FilterIndex = 1;
if (dialog.ShowDialog() == true)
{
int? calendarId = null;
int? seriesId = null;
DateTime date = (DateTime)this.datPlayDate.SelectedValue;
foreach (Bass.Web.DataModel.InterteamCalendar cal in this.calendarsDomainDataSource.DataView)
{
if (date == cal.Date)
{
calendarId = cal.InterteamCalendarId;
}
}
RadMenuItem item = o as RadMenuItem;
if (item.Name != "")
{
seriesId =
int.Parse(item.Name);
}
Bass.Web.Services.
BASSDomainContext domainContext3 = new Web.Services.BASSDomainContext();
EntityQuery<Bass.Web.DataModel.ExportInterteamOnOfficialResults_Result> exportQuery;
exportQuery = domainContext3.GetExportInterteamOnOfficialResultsQuery(calendarId, seriesId);
domainContext3.Load(exportQuery, lo =>
{
if (!lo.HasError)
{
gridExport.ItemsSource = domainContext3.ExportInterteamOnOfficialResults_Results;
gridExport.Rebind();
using (Stream stream = dialog.OpenFile())
{
GridViewExportOptions exportOptions = new GridViewExportOptions();
exportOptions.Format = format;
exportOptions.ShowColumnFooters =
true;
exportOptions.ShowColumnHeaders =
true;
exportOptions.ShowGroupFooters =
true;
gridExport.Export(stream, exportOptions);
}
}
},
false);
}
}