Home Forums WinForms controls Xceed Grid for WinForms Treeview for grid

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17629 |

    Hello,

    I have a datatable whose rows have a uniqueid and a parentid.

    any row whith a parentid of zero is a top level row (it is not a child of any other row).

    Any row that has a parentid is a child of the row which has that id as its unique id etc (a foreign key).

    A row in the datatable can have any number of child items which could recurse forever.

     

    I am looking for a solution that will allow me to bind the datatable to a grid control and for the grid control to sort the parent / child relationships and show them as collapsable groups using ‘DetailGridTemplates’.

    I also require the ability to add further rows as child rows into the grid.

     

    I have looked at the ‘GridTreeViewBrowser’ example and downloaded another example project from

    http://www.xceedsoft.com/cs/download/XceedGrid/CSharp/Grid TreeView.zip

    Am I asking too much of the xceed grid?

     

    Many thanks

    Steve

    Imported from legacy forums. Posted by Steve (had 1052 views)

    User (Old forums)
    Member
    Post count: 23064

     

    here is an example – this will create a datatable which joins to itself with a releationship

    However the grid cannot handle the children – it repeats them.

    Is this not possible?

     

                // create data
                ds_test = new DataSet();
                dt_test = new DataTable(“test_table”);
                dt_test.Columns.Add(“id”, typeof(int));
                dt_test.Columns.Add(“pid”, typeof(int));
                dt_test.Rows.Add(1, null);
                dt_test.Rows.Add(2, 1);
                dt_test.Rows.Add(20, 1);
                dt_test.Rows.Add(30, 1);
                dt_test.Rows.Add(40, 30);
                ds_test.Tables.Add(dt_test);

                // create relationship
                ds_test.Relations.Clear();
                rel_test = new DataRelation(“parent-to-child”,
                                            ds_test.Tables[“test_table”].Columns[“id”],
                                            ds_test.Tables[“test_table”].Columns[“pid”], false);
                ds_test.Relations.Add(rel_test);

                // set bindings for master
                dg_test.SetDataBinding(ds_test.Tables[“test_table”], “”);

                // start init
                dg_test.BeginInit();
                dg_test.SynchronizeDetailGrids = false;

                // set up the detail grid
                dgt_test = new DetailGrid();
                dgt_test.SetDataBinding(ds_test.Tables[0], “parent-to-child”);
                dgt_test.HeaderRows.Add(new ColumnManagerRow());
                dgt_test.AutoCreateColumns = false;

                // create columns for master
                dg_test.AutoCreateColumns = false;
                DataBoundColumn column1 = new DataBoundColumn(“parent-to-child”);
                column1.Visible = false;
                dg_test.Columns.Add(column1);
                DataBoundColumn pidColumn = new DataBoundColumn(“pid”);
                dg_test.Columns.Add(pidColumn);
                dg_test.Columns[“pid”].Visible = false;
                dg_test.Columns[“pid”].Title = “xxx”;
                dg_test.Columns[“pid”].Width = 100;
                dg_test.Columns[“id”].Visible = true;

                // create columns for detail
                DataBoundColumn pidColumn1 = new DataBoundColumn(“pid”);
                dgt_test.Columns.Add(pidColumn1);
                dgt_test.Columns[“pid”].Visible = true;
                dgt_test.Columns[“pid”].Title = “Parent”;
                dgt_test.Columns[“pid”].Width = 100;

                DataBoundColumn idColumn1 = new DataBoundColumn(“id”);
                dgt_test.Columns.Add(idColumn1);
                dgt_test.Columns[“id”].Visible = true;
                dgt_test.Columns[“id”].Title = “Unique”;
                dgt_test.Columns[“id”].Width = 100;

                
                // sync and end
                dg_test.DetailGridTemplates.Add(dgt_test);
                dg_test.UpdateDetailGrids();
                dg_test.EndInit();

    Imported from legacy forums. Posted by Steve (had 997 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.