I'm using WPF and I have a DataGrid binded to an Object List with each column to each property:
<DataGrid x:Name="Docs" Margin="29,211,25,66" IsReadOnly="False" AutoGenerateColumns="False"
DataContext="{Binding Source={StaticResource Rutine}}" CanUserReorderColumns="False"
ItemsSource="{Binding Documents,Mode=TwoWay}">
<DataGrid.Columns>
<DataGridTextColumn Header="Document Type" Binding="{Binding DocumentType}" />
<DataGridTextColumn Header="Document (Name)" Binding="{Binding DocumentName}" /></DataGrid.Columns></DataGrid>
public IList<CSDoc> Documents
{
get
{
return _Documents;
}
set
{
_Documents = value;
NotifyPropertyChanged("Documents");
}
}
public class CSDoc
{
public string DocumentType{ get; set; }
public string DocumentName{ get; set; }
}
I allow the user to change the data, so that it can later be exported to an xlsx file.
But I need a DataTable Object to do that.
Another problem is that I need the Headers as they are, because the xlsx file is later uploaded to another system that makes validations with spaces and parentheses.
Is there a way to create the DataTable from the DataGrid user view without cycling each cell?
And because of each Header, without the Object List being cycled as well...