Search code examples
c#winformsdevexpressdevexpress-windows-ui

In DevExpress Controls, the Property VisibleIndex of BandedGridColumn does not work


I write the following code to hide the particular column:

(_view as BandedGridView).Columns[j].VisibleIndex = -1;

And this worked

However, I want to change the order of the column by following code:

(_view as BandedGridView).Columns[j].VisibleIndex = i;

But this does not worked

Ask for help, thanks


Solution

  • According to documentation, assigning value to VisibleIndex property greater than -1 attempting to move the column has no effect:

    Setting the VisibleIndex property to -1 hides the column. In this case, the column header is displayed within the Customization Form (provided that the column's OptionsColumn.ShowInCustomizationForm option is enabled).

    Note that assigning values greater than -1 has no effect. To change the column's position among visible columns in Banded Grid Views, use the GridBandColumnCollection.MoveTo method.

    Assume that you have a GridBand in designer:

    private DevExpress.XtraGrid.Views.BandedGrid.GridBand GridBand1;
    

    You can use MoveTo method to change column position instead:

    GridBand1.Columns.MoveTo(i, [BandedGridColumn]);
    

    NB: The [BandedGridColumn] refers to DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn object names declared in the designer.

    Similar issue:

    Strange Behavior when setting VisibleIndex in BandedGridView after user customization