Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
450
Need help in arranging Columns in a Multiband Grid
posted

I have a grid which has 4 bands and the columns in band[3] are not arranged in order as in its parent bands. My primary requirement is to arrange the Band[3] columns.

This is a part of "Export to Excel" code. The grids are already displayed in the form.

I have tried the below approach -

private UltraGrid rearrangeCol(UltraGrid grid)
        {
            int bandCount = grid.DisplayLayout.Bands.Count;
            int band = 0;
            List<String> colPos = new List<string>();
            for (int i = grid.DisplayLayout.Bands[band].Columns["EndurEndInv"].Index; i < grid.DisplayLayout.Bands[band].Columns.Count; i++)
            {
                colPos.Add(grid.DisplayLayout.Bands[band].Columns[i].Key);
            }
            band++;
            while (band < bandCount)
            {
                int initialColPos = grid.DisplayLayout.Bands[band].Columns["EndurEndInv"].Index;
                for (int i = initialColPos, j = 0; i < grid.DisplayLayout.Bands[band].Columns.Count && j < colPos.Count; i++, j++)
                {
                    if(!grid.DisplayLayout.Bands[band].Columns[i].Key.Equals(colPos[j], StringComparison.InvariantCulture))
                    {
                        grid.DisplayLayout.Bands[band].Override.AllowColSwapping = Infragistics.Win.UltraWinGrid.AllowColSwapping.WithinBand;
                        int xcngPos = grid.DisplayLayout.Bands[band].Columns[colPos[j]].Index;
                        grid.DisplayLayout.Bands[band].Columns.Insert(i, "Temp");
                        grid.DisplayLayout.Bands[band].Columns[xcngPos + 1].Swap(grid.DisplayLayout.Bands[band].Columns[i]);
                        grid.DisplayLayout.Bands[band].Columns.Remove("Temp");
                        grid.DisplayLayout.Bands[band].Override.AllowColSwapping = Infragistics.Win.UltraWinGrid.AllowColSwapping.Default;

                    }
                    else
                        continue;
                }
                band++;

            };
            return grid;
        }

 

Actually, nothing happens when I use SWAP, the keys, index remains same.

Is there any better approach?

Parents
  • 469350
    Offline posted

    Hi,

    I'm not sure I understand what you are trying to do. If the columns are in the order you want on the screen, then they should export to Excel in the same order. Are you saying that they are exporting in a different order than they are shown in the on-screen grid? If so, then something in your code must be changing the order when you are exporting.

    The code you posted here is using the grid's DisplayLayout, so this will affect the on-screen grid. If you called this code at any point after the export process began, it will have no effect on the export, because the way exporting works is that the exporter creates a clone of the grid's DisplayLayout. So the cloned layout would not be affected by any changes you make to the grid's DisplayLayout after the clone is created.

    If you want to modify the export without modifying the on-screen grid, then you should use the ExportStarted event of the UltraGridExcelExporter and use the Layout which is passed into the event via the event args. This is the cloned layout. .

Reply Children