Home Forums WinForms controls Xceed Grid for WinForms Treeview for grid Reply To: Treeview for grid

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)