internal void RequestSubformClosing(DataGridViewSubformCell sender, SubformClosingEventArgs e)
 {
     if (SubformClosing != null)
     {
         SubformClosing(sender, e);
     }
 }
示例#2
0
 public void CloseForm()
 {
     if (this.OwningColumn == null)
     {
         return;
     }
     if (form != null)
     {
         //Fire the subformclosing event and check for cancels
         SubformClosingEventArgs ea = new SubformClosingEventArgs(form);
         ((DataGridViewSubformColumn)this.OwningColumn).RequestSubformClosing(this, ea);
         if (ea.Cancel)
         {
             _subformshowing = true;
             return;
         }
         //remove the subform from the data gridview
         DataGridView.Controls.Remove(form);
         //dispose of the subform
         form.Dispose();
         form = null;
         //set the height of the row to the correct value
         if (((DataGridViewExtension)DataGridView).SubFormColumns.Count() > 1)
         {
             if (RowSubformCells.Max(r => r.SubformHeight) > 0)
             {
                 OwningRow.Height = RowSubformCells.Max(r => r.SubformHeight) + heightBeforeShowSubForm;
             }
             else
             {
                 OwningRow.Height        = heightBeforeShowSubForm;
                 heightBeforeShowSubForm = 0;
             }
         }
         else
         {
             OwningRow.Height        = heightBeforeShowSubForm;
             heightBeforeShowSubForm = 0;
         }
         //reset alignment for each cell
         if (OwningRow.Cells.Cast <DataGridViewCell>().Where(r => r.GetType() == typeof(DataGridViewSubformCell)).Cast <DataGridViewSubformCell>().Where(r => r.SubformShowing).Count() == 0)
         {
             for (int i = 0; i < alignmentBeforeShow.Length / 2; i++)
             {
                 if (OwningRow.Cells.Cast <DataGridViewCell>().Where(r => r.OwningColumn ==
                                                                     (DataGridViewColumn)alignmentBeforeShow[i, 1]).Count() > 0)
                 {
                     OwningRow.Cells.Cast <DataGridViewCell>().Where(r => r.OwningColumn ==
                                                                     (DataGridViewColumn)alignmentBeforeShow[i, 1]).First().Style.Alignment
                         = (DataGridViewContentAlignment)alignmentBeforeShow[i, 0];
                 }
             }
         }
         //reposition all subforms below this one
         for (int i = DataGridView.CurrentCell.RowIndex + 1; i < DataGridView.Rows.Count; i++)
         {
             foreach (DataGridViewSubformColumn col in ((DataGridViewExtension)DataGridView).SubFormColumns)
             {
                 DataGridViewSubformCell cell = ((DataGridViewSubformCell)DataGridView.Rows[i].Cells[col.Index]);
                 if (cell.SubformShowing)
                 {
                     cell.PositionSubform();
                 }
             }
         }
     }
 }