Home Forums WinForms controls Xceed Grid for WinForms Grouping columns programatically Reply To: Grouping columns programatically

User (Old forums)
Post count: 23064

Hi André,

Thanks for the response. However the code does not seem to work in all cases. I need to use the grid in unbound mode and our forms are dynamically generated so we can’t use the designer. It’s quite hard to pick exactly what code generate by the designed is need and what is not. Here’s an example of code where I think it should be grouped on column item1, but is not:

  class Program {

    static void Main(string[] args) {

      // create the form

      Form form = new Form();

      // create and configure the grid

      GridControl grid = new GridControl();

      grid.Dock = DockStyle.Fill;

      grid.HeaderRows.Add(new GroupByRow());

      grid.HeaderRows.Add(new ColumnManagerRow());


      // add some columns

      grid.Columns.Add(new Column(“item1”));

      grid.Columns.Add(new Column(“item2”));

      grid.Columns.Add(new Column(“item3”));

      // add some rows

      var items = new string[] {“one”, “two”, “three”};

      foreach (var item in items) {

        DataRow row = grid.DataRows.AddNew();

        row.Cells[“item1”].Value = “const”;

        row.Cells[“item2”].Value = item;

        row.Cells[“item3”].Value = item;


      grid.DataRows.AddNew(); // seems to be necessary to make last row appear

      // suggested code

      Xceed.Grid.Group group1 = new Xceed.Grid.Group();

      Xceed.Grid.GroupManagerRow groupManagerRow1 = new Xceed.Grid.GroupManagerRow();

      group1.Collapsed = true;

      group1.GroupBy = “item1”;







BTW cool bunny picture! 



Imported from legacy forums. Posted by Robert (had 602 views)