Home Forums WinForms controls Xceed Grid for WinForms Master detail using collections Reply To: Master detail using collections

User (Old forums)
Member
Post count: 23064

This seems fine.  The only thing that could be done differently is to load all the data into you DataSet when first loading your form, and then simply bind the detail girds as it gets expended.

e.g.:

    private void Form1_Load( object sender, EventArgs e )
    {
     
      detailGridTemplate1.Collapsed = true;
      detailGridTemplate1.CollapsedChanged += new EventHandler( detailGridTemplate1_CollapsedChanged );
     
      gridControl1.SynchronizeDetailGrids = false;

      gridControl1.SetDataBinding( this.northwindDataSet.Suppliers, “” );

      //Assuming a Suppliers (master) / Products (detail) relationship called “SuppliersProducts” in the DataSet.
      this.suppliersTableAdapter.Fill( this.northwindDataSet.Suppliers );
      this.productsTableAdapter.Fill( this.northwindDataSet.Products );
    }

    void detailGridTemplate1_CollapsedChanged( object sender, EventArgs e )
    {
      DetailGrid grid = sender as DetailGrid;
      if( !grid.Collapsed )
        //This will permit to fill the DetailGrid with the data related to the parent row, by using the relationship
        grid.SetDataBinding( grid.ParentDataRow.Cells[ “SuppliersProducts” ].Value, string.Empty );
      else
        grid.SetDataBinding( null, string.Empty );     
    }

Imported from legacy forums. Posted by André (had 4374 views)