Priyam
Priyam

Reputation: 23

Need help in arranging Columns in a Multiband Infragistics UltrawinGrid

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?

Upvotes: 1

Views: 3210

Answers (1)

Steve
Steve

Reputation: 216302

Yes, to rearrange to position of colums you need to work on

grid.DisplayLayout.Bands[index].Columns[colName].Header.VisiblePosition = newPos;

no need to swap the column positions, just rearrange the Header position.

This code below has not been tested and I write as an example

    private UltraGrid rearrangeCol(UltraGrid grid)
    {
        int bandCount = grid.DisplayLayout.Bands.Count;
        int band = 1;

        UltraGridBand b0 = grid.DisplayLayout.Bands[0];
        while (band < bandCount)
        {
            UltraGridBand b = grid.DisplayLayout.Bands[band]
            for (int i = b0.Columns["EndurEndInv"].Index; i < b0.Columns.Count; i++)
            {
                string colKey = b0.Columns[i].Key;
                if(b.Columns.Exists(colKey))
                    b.Columns[colKey].Header.VisiblePosition = 
                                   b0.Columns[colKey].Header.VisiblePosition;
            }
            band++;
        }
        return grid;
    }

Upvotes: 1

Related Questions