DevExpress.Xtragrid点击Band时对子列进行排序

DevExpress.Xtragrid点击Band时对子列进行排序

根据其官网中的代码只能在第一次点击时有效,之后就无法正常排序,后来发现需要前取消所有其他列的排序才能对当前列进行排序。
所以对其代码做了小小的更改.

 private void advBandedGridView1_MouseDown(object sender, MouseEventArgs e)
        {
            Point pt = new Point(e.X, e.Y);
            BandedGridHitInfo hit = advBandedGridView1.CalcHitInfo(e.Location);


            if (!hit.InBandPanel)
            {
                return;
            }

            GridBand gb1 = hit.Band;
            if (gb1.Children.VisibleBandCount > 0) //是否有下级Band
            {
                return;
            }
            for (int i = 0; i < advBandedGridView1.Columns.Count; i++) //取消当前列以外的所有列的排序
            {
                if (advBandedGridView1.Columns[i].SortOrder == DevExpress.Data.ColumnSortOrder.None)
                {
                    continue;
                }
                    if (advBandedGridView1.Columns[i].FieldName != gb1.Columns[0].FieldName)
                        advBandedGridView1.Columns[i].SortOrder = DevExpress.Data.ColumnSortOrder.None;
                
            }

            if (gb1.Columns[0].SortOrder == DevExpress.Data.ColumnSortOrder.Ascending)
                gb1.Columns[0].SortOrder = DevExpress.Data.ColumnSortOrder.Descending;
            else
                gb1.Columns[0].SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;


        }


 

你可能感兴趣的:(DevExpress控件)