Group rows by specific column without dragging

Posted by: mikenap on 8 September 2017, 3:26 pm EST

  • Posted 8 September 2017, 3:26 pm EST

    I'd like to automatically group the rows in a spread grid automatically without dragging the column to the top. I'd like to group by a column called name, and group all subsequent rows with the same name. I currently can do this by dragging the name column to the top, using the standard grouping procedure, but is there a way to group by the first column by default, without needing to drag the column to the top?

    Right now I have this, but would like to replace with code that automatically groups by column 0, without having the user drag the column to the top.

    fpSpread1.AllowColumnMove = true;
    fpSpread1.Sheets[0].GroupBarInfo.Visible = true;
    fpSpread1.Sheets[0].AllowGroup = true;
    fpSpread1.Sheets[0].GroupingPolicy = FarPoint.Win.Spread.Model.GroupingPolicy.CollapseAll;


    I'm currently using Spread for Win Forms v. 6.0, .NET 4.0 and Visual Studio 2012
  • Replied 8 September 2017, 3:26 pm EST

    I used this code, but it removed sorting and filtering for the spread grid:

    var gm = new FarPoint.Win.Spread.Model.GroupDataModel(fpSpread1.ActiveSheet.Models.Data);
    var sort = new FarPoint.Win.Spread.SortInfo[1];

    sort[0] = new FarPoint.Win.Spread.SortInfo(0, true);
    gm.Group(sort, System.Collections.Comparer.Default);
    fpSpread1.ActiveSheet.Models.Data = gm;
    fpSpread1.Sheets[0].GroupingPolicy = FarPoint.Win.Spread.Model.GroupingPolicy.CollapseAll;
  • Marked as Answer

    Replied 8 September 2017, 3:26 pm EST

    Hello,

    Grouping and sorting do not work together. Grouping is a type of sorting. When grouping is on, clicking on column headers( or through code as shown in attached sample) will cause grouping not sorting. Thus, these features do not work together.

    When grouping is turned on, some of the interactive features including sorting do not work. However, there is not a way to display the sort indicator/ filter dropdown in the column header as the column headers are now dragged and used to perform grouping and are not doing an interactive sort that displays the sort indicator in the column header.

    Similarly even filtering is not possible when the grouping is turned on.

    Hope it clarifies. And please have a look at attached sample for grouping by code:-

        private void button1_Click(object sender, EventArgs e)
    {
    // Grouping at runtime
    FarPoint.Win.Spread.Model.GroupDataModel gm = new FarPoint.Win.Spread.Model.GroupDataModel(fpSpread1.Sheets[0].Models.Data);
    // Grouping by CategoryID Column which is column index 3
    FarPoint.Win.Spread.SortInfo[] si = new FarPoint.Win.Spread.SortInfo[] { new FarPoint.Win.Spread.SortInfo(3, true) };
    gm.Group(si);
    fpSpread1.Sheets[0].Models.Data = gm;
    }


    Hope it helps.

    Thanks,
    Reeva
    2017/08/SpreadWin_GroupingByCode.zip
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels