Home Forums WinForms controls Xceed Grid for WinForms Adding new rows into a Master/Detail GridControl Reply To: Adding new rows into a Master/Detail GridControl

User (Old forums)
Member
Post count: 23064

You need to use an event (like a button click) to add a new row to the mater grid.  Then use the InitializingDetailGrid event to add new rows to the corresponding detail grid.

e.g.:

    private void button1_Click( object sender, EventArgs e )
    {
      gridControl1.InitializingDetailGrid += new InitializingDetailGridEventHandler( gridControl1_InitializingDetailGrid );

      Xceed.Grid.DataRow masterRow = gridControl1.DataRows.AddNew();
      masterRow.Cells[ 0 ].Value = someValue;
      masterRow.EndEdit();
    }

    void gridControl1_InitializingDetailGrid( object sender, InitializingDetailGridEventArgs e )
    {
      gridControl1.InitializingDetailGrid -= new InitializingDetailGridEventHandler( gridControl1_InitializingDetailGrid );

      Xceed.Grid.DataRow detailRow = e.Grid.DataRows.AddNew();
      detailRow.Cells[ 0 ].Value = someOtherValue;
      detailRow.Cells[ 1 ].Value = e.Grid.ParentDataRow.Cells[ 0 ].Value;
      detailRow.EndEdit();     
    }
 

 

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