Skip to main content Skip to footer

Moving C1Flexgrid Between Forms

Our customers at times comes up with the requirement of dragging the grid controls between two forms and place them side by side so that they can compare the data and make the required changes in the grid. In this blog we explain the implementation to achieve the same with the help of C1FlexGrid for Winforms and FlowLayoutPanel which dynamically lays out its contents/controls horizontally or vertically depending on its placement on the form. To implement this we use an MDI application with the ability to add 'n' number of child forms; each form containing a FlowLayoutPanel with C1FlexGrid inside the same. As soon as a child form is added to the MDI parent form we set the FlowlayoutPanel's AllowDrop property to true to allow the FlowLayoutPanel to accept the object that the user drags onto the same.

 childFlowLayoutPanel.AllowDrop = true;  

Further in C1FlexGrid's MouseCaptureChanged event we set the FlowLayoutPanel's DragDropEffects to specify that the control ( sender is C1FlexGrid here) from the drag source is moved to drop target.


void \_c1FlexGrid\_MouseCaptureChanged(object sender, EventArgs e)  
{  
    childFlowLayoutPanel.DoDragDrop((sender as C1FlexGrid), DragDropEffects.Move);  
}  
void childFlowLayoutPanel_DragEnter(object sender, DragEventArgs e)  
{  
    e.Effect = DragDropEffects.Move;    // to show dragging effects  
}  

Finally we capture the DragDrop event for FlowLayoutPanel in the target form. DragDrop event fires once the control is dropped and drag-drop operation is completed.


void childFlowLayoutPanel_DragDrop(object sender, DragEventArgs e)  
{  
    C1FlexGrid data = (C1FlexGrid)e.Data.GetData(typeof(C1FlexGrid));  
    FlowLayoutPanel _destination = (FlowLayoutPanel)sender;  
    FlowLayoutPanel _source = (FlowLayoutPanel)((C1FlexGrid)data).FindForm().Controls["childFlowLayoutPanel"];  

    if (\_source != \_destination)  
    {  
       // Add control to panel  
       _destination.Controls.Add(data);  
    }  
}

DownloadSample_CS DownloadSample_VB

MESCIUS inc.

comments powered by Disqus