0

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jack Chen
  • 11
  • 8

2 Answers2

2

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

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61
0
GridCell CurrentCell { get; set ; }
private void gridView1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
    {
         CurrentCell = null;
        GridHitInfo hitInfo = gridView1.CalcHitInfo(e.Location);
        if (hitInfo.HitTest == GridHitTest.RowCell)
        {
            CurrentCell = new GridCell(hitInfo.RowHandle, hitInfo.Column);
        }
    }
}

Result: gridView1.FocusedRowHandle = CurrentCell.RowHandle;

Phu Thien
  • 1
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – alea Jun 16 '23 at 16:56