Search code examples
c#infragistics

UltraGrid VisiblePosition not change when column moved


I have a c# project and within this project I have a dialog with an ultragrid. The grid has 3 groups and each group have more than 4 columns. Columns of the Ultragrid

I can move the columns and change the order of the columns. Everything works fine. At the end i want to save the definition of the columns, if the column is hidden and the position of the column.

I iterate over the list of columns and save the column.Hidden property and the column.Header.VisiblePosition property. The problem is that the visiblePosition value doesn't match to the position in the grid, which you see in the UI.

I moved some columns to the left and right, but the visiblePosition is the same as the beginning. The UI shows the correct order of each column and the column position changed but the value of the property didn't change.

Maybe the problem exist because i use columnGroups.

Thank you


Solution

  • UltraWinGrid has a two methods to solve this kind of problems.
    They are the SaveAsXml and LoadFromXml from the DisplayLayout class.

    You can use them to save and restore the layout of your grid.
    For example, in the Dispose event of your form you can add a call to

    public void SaveLayout(UltraGrid grd, string layoutFile)
    {
        if (grd.DataSource != null)
            grd.DisplayLayout.SaveAsXml(layoutFile, PropertyCategories.All);
    }
    

    While in the InitializeLayout event of your grid you could restore the layout with

    public void LoadLayout(UltraGrid grd, string layoutFile)
    {
        if (File.Exists(layoutFile))
            grd.DisplayLayout.LoadFromXml(layoutFile, PropertyCategories.All);
    }
    

    Depending on your specific needs you can fine tune the PropertyCategories enum to choose only the property group you want to save/restore.