I have a DataGrid
implemented in a WPF-window inside a VSTO-AddIn, which is supposed to preview data to the user before it is pasted to an existing Excel-sheet. The CanUserSortColumns-Property
is set to true
, so the user is able to rearrange the columns before they are read out and pasted to the sheet. However, when I read out the DataRows
from the DataGrid
, as shown below, the columns are back in their original position.
object[,] dataArray = new object[allRows, allCols];
for (int r = 0; r < allRows; r++)
{
DataRow row = ClientGrid.Rows[r];
for (int c = 0; c < allCols; c++)
{
dataArray[r, c] = row[c];
}
}
Here is my question: Is there any way to fix this the quick way or at least to track the changes of column display indices in order to rearrange the column order in the code with every change of the columns display order?
I've already tried working something out with the DisplayIndex
-property but I did not quite get the hang of the numbers it spits out.