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?