Search code examples
c#asp.netdevexpressgroupingaspxgridview

How to get a ASPxGridview column GroupIndex in C#


I have got a aspxgridview which I can group columns on , how do I get the column that I have grouped groupindex I know how to check if its grouped or not , now I just need to find out at which group level it is on in either 1 ,2 ,3 ,4 ,5 ?

I have already tried something like this :

foreach (GridViewColumn column in ASPxGridView1.VisibleColumns) {
     ASPxLabel1.Text = ASPxGridView1.Columns[column.Caption].Grid.IsGroupRow(column.VisibleIndex).ToString();
}

Solution

  • The following code shows how to ungroup grouped columns and how to see and/or set the GroupIndex. If the column is grouped then it has a GroupIndex >= 0. If the column is not grouped then it has GroupIndex of -1. GroupIndex is the GroupLevel. A GroupIndex of 0 is at the root level.

        void GridView_ClearColumnGroups(ASPxGridView theGridView)
        {
            foreach (GridViewDataColumn gvdc in theGridView.Columns)
            {
                if (gvdc != null && gvdc.GroupIndex >= 0)
                {
                    gvdc.GroupIndex = -1;
                    gvdc.UnGroup();
                }
            }
        }
    

    Here is the documentation for GridViewDataColumn.GroupIndex.