See attached sample.
If I add columns to the xamDataGrid from the code behind, the position of the column are never the same if I change the position of the available columns before adding new ones.
Here is how to reproduce the problem.
1) Launch the sample. You should have a grid with 5 columns labelled from 0 to 4. (0, 1, 2, 3, 4)
2) Drag and drop the column #2 to the beginning of the grid (2, 0, 1, 3, 4)
3) Hit the button at the top many times. When you click the button, I remove column 3 and 4 from the layout et re-add them.
4) You will see that sometimes, the last column will be 3 and sometimes, it will be 4. Why?.
Note:
I tried to play with the property Column or ActualPosition of the Field without success.
The problem isn't there if you do not change the position of column 2 (or any other column).
I need to dynamically add and remove columns in my application and these columns must be added at runtime. Is there a way to position them in the order that I want?
Hello,
I have noticed that you posted this a while ago. Please note, we are making efforts to ensure all posts are addressed by an Infragistics expert. We believe that the other community members could benefit from this thread as well.
Regarding your issue I would suggest you to set the ActualPosition property on the Field once you add field to the fields collection.
So in btnAddCol_Click event in your sample please use below line of code
templateXamGrid.FieldLayouts[0].Fields.Add(uf); uf.ActualPosition = new FieldPosition(colNum,0,1,1);
Let me know if you have any questions.