How can I keep changed column order during insert?

I append a column using grid->InsertColumn(grid->ColumnCount) which shows the new column and increments grid->ColumnCount.

If I then call grid->ColumnAtPosition(grid->ColumnCount-1) for the new last column, I get an out of bounds exception.  If I call grid->SetColumnOrder() after inserting the new column, ColumnAtPosition() doesn't crash, but returns the value established by the latest SetColumnOrder(), not my original order before dragging columns to new positions.  If I call ResetColumnOrder() (twice) before inserting, ColumnAtPosition() returns usable values, but now my column order is back to the original creation order, not the order after dragging columns to new positions before inserting a new column.

Do I need to do something else before or after inserting a new column?  What is the recommended way to maintain the current column order when I insert or append a new column?  Thanks in advance.

SetColumnOrder needs to be called to set your reference column order after all columns are setup in the grid. When you first reposition columns and then add a column and then call SetColumnOrder, this will not remember the column moving done before the call to SetColumnOrder.

Thanks for the confirmation Bruno.