I am copying xamDataGrid's data to excel. I am doing it field by field. In order to do so, I have the following loop:
foreach (Field field in xamDataGrid.DefaultFieldLayout.Fields)
{
....
}
However, the ordering of the fields in xamDataGrid.DefaultFieldLayout.Fields is different from what is visible in the grid. Is there a way to ensure that the fields are copied to excel in the same order as the currently active layout. I guess, something like:
foreach (Field field in xamDataGrid.CurrentFieldLayout.Fields) ..... so, if the user has moved some fields around, the new field ordering is used.
Thanks.
Hello Jay6447,
I have been looking into your enquiry and if you haven’t explicitly created your own FiledLayout in the FieldLayouts collection, or if you have not changed the data source’s data type, the DefaultFieldLayout (FieldLayouts[0]) will be used. The thing why you are not getting the new Field however is different. When you drag/drop a Field through the UI the Fields do not change their index in the Fields collection, but rather their ActualPosition property is changed.
Another thing I should point out that there is built-in functionality for exporting the XamDataGrid data to Excel via the DataPresenterExcelExporter: http://help.infragistics.com/NetAdvantage/WPF/2012.2/CLR4.0/?page=xamDataPresenter_Export_a_DataPresenter_Control_to_Excel.html
Please let me know, if I can be of any further assistance on the matter.
Thanks - I will check it out.
There is a single saved layout that is being loaded in Code Behind.
Even if I do:
int cnt = FieldLayouts.Count
forearch (Field field in FieldLayout[cnt - 1].Fields) // to get the latest saved layout
I am getting the value for cnt as 1 and then the same output as before.