- Home
- Forum
- Xamarin.Forms
- Failed to Export
Failed to Export
Hi , i am newbie for syncfusion control. recently i wish add a export function for my data grid, but it was failed and the error message prompted "System.NullReferenceException" has been thrown
//Data Grid xaml //////////////////////////////////////////////////////////
<syncfusion:SfDataGrid x:Name="dataGridStock"
AutoGenerateColumns="False"
SelectionUnit="Row"
ColumnSizer="Auto"
SelectionMode="Single"
RowHeight="30"
AllowSorting="True"
IsVisible="false"
GridStyle="{Binding customStyle}"
ItemsSource="listStockTakeItem"
>
<syncfusion:SfDataGrid.Columns>
<syncfusion:GridTextColumn MappingName="StockCode" HeaderText=" StockCode" HeaderTextAlignment="Center"/>
<syncfusion:GridTextColumn MappingName="ReferenceCode" HeaderText="ShortCode"/>
<syncfusion:GridTextColumn MappingName="WarehouseCode" HeaderText="Warehouse"/>
<syncfusion:GridNumericColumn MappingName="Qty" HeaderText="Qty" NumberDecimalDigits="0"/>
<syncfusion:GridTextColumn MappingName="Description" HeaderText="Description" HeaderTextAlignment="Center"/>
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
</StackLayout>
//Export Button
private void buttonExport_Clicked(System.Object sender, System.EventArgs e)
{
DataGridExcelExportingController excelExport = new DataGridExcelExportingController();
if (!dataGridStock.IsVisible)
{
dataGridStock.GetType().GetMethod("CreateCollectionView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(dataGridStock, new object[] { dataGridStock.ItemsSource });
}
var excelEngine = excelExport.ExportToExcel(this.dataGridStock);
var workbook = excelEngine.Excel.Workbooks[0];
MemoryStream stream = new MemoryStream();
workbook.SaveAs(stream);
workbook.Close();
excelEngine.Dispose();
Xamarin.Forms.DependencyService.Get<ISave>().Save("DataGrid.xlsx", "application/msexcel", stream);
}
//Data source
listStockTakeItem = dbService.GetStockTakeItemListBymobileDocID(mobileDocID);
foreach (var item in listStockTakeItem)
{
item.PriceInfo = "RM" + DataFormat.DecimalToText(item.UnitPrice, 2);
if (item.DiscountRate > 0)
item.PriceInfo += " Discount : " + DataFormat.DecimalToText(item.DiscountRate, 2) + "%";
}
// lstViewStockTakeData.ItemsSource = listStockTakeItem;
dataGridStock.ItemsSource = listStockTakeItem;
Hi Anson,
We have analyzed your query. It seems that you have set ItemsSource in both XAML and code-behind. In XAML, it might be setting an improper binding for the ItemsSource property please refer the below code snippet. Could you please replicate the issue again after removing one of them or by using proper binding?. Also could you please verify the database related codes are correct?.
| ItemsSource="listStockTakeItem" |
If you are still encountering the issue, could you please provide us with the stack trace and call stack for the exception?. This will help us to validate the issue at our end.
Regards,
Diwakar V
after i removed the xaml itemsource error still exist , my itemsouce is correct .. all the while i using for my project
Anson,
We suspect that the issue may have been caused by the platform-specific implementation of the Save method. To assist you further, could you please provide us with the stack trace and call stack for the exception?
Additionally, it would be helpful if you could share the code snippets related to the Save method. This will allow us to validate and provide you with an appropriate solution.
- 3 Replies
- 2 Participants
-
AN ANSON
- Jul 4, 2023 03:53 AM UTC
- Jul 6, 2023 12:26 PM UTC