drag and drop

Hi
how to implement scenarios

I have two Forms (Form200 - source and Form__TreeViewAdv1 - destination)

1
I need to move the contents of any cell from GGC   and  source_textBox1  with my mouse
from source_gridGroupingControl1 (Form200)  and source_textBox1  to destination_gridGroupingControl1 (Form__TreeViewAdv1) to  dropped line   Columns "drag_and_drop_IN" -
to be completed

and start the event   MessageBox.Show("I introduced the value  " +new_value+ " in the column and row : " + rc);

2. 


I need to move the contents of any cell from GGC   and  source_textBox1  with my mouse
from source_gridGroupingControl1 (Form200)  and source_textBox1  to treeViewAdv1 (Form__TreeViewAdv1)


and start the event 


if new value drop in treeViewAdv1  
the name is the same


MessageBox.Show("I introduced the value  " +new_value+ " in treeViewAdv1 drop  name  : " + drop _name);


please help
Gregory










Attachment: test_TreeViewAdv_95637871.rar

3 Replies

SK Senthil Kumaran Rajan Syncfusion Team August 10, 2018 03:22 PM UTC

Hi Gregory, 
 
Query 1 : I need to move the contents of any cell from GGC   and  source_textBox1  with my mouse from source_gridGroupingControl1 (Form200)  and source_textBox1  to destination_gridGroupingControl1 (Form__TreeViewAdv1) to  dropped line   Columns "drag_and_drop_IN" - to be completed 
 
To DragDrop the GridGroupingControl cell value to other controls, you could use the TableControlMouseDown event to copy the cell value and use DragDop event to get the dropped value the you could set that value to record using SetValue method. Please refer to the below code example,  
  
Form200  
Code example  
this.gridGroupingControl1.TableControlMouseDown += gridGroupingControl1_TableControlMouseDown;  
this.gridGroupingControl1.DragEnter += GridGroupingControl1_DragEnter;  
  
void gridGroupingControl1_TableControlMouseDown(object sender,GridTableControlMouseEventArgs e)  
{  
    GridGroupingControl grid = sender as GridGroupingControl;  
  
    if (grid != null)  
    {  
        GridTableControl tableControl = grid.TableControl;  
        Point pt = new Point(e.Inner.X, e.Inner.Y);  
        int row, col;  
        if (tableControl.PointToRowCol(pt, out row, out col))  
        {  
            GridTableCellStyleInfo style = tableControl.Model[row, col];  
            //checks if the cell in which the MouseDown event is a RecordRowHeaderCell.  
            //If yes, then begins the DragDrop operation.  
            if(style.TableCellIdentity != null && style.TableCellIdentity.DisplayElement.Kind ==DisplayElementKind.Record)  
            {  
                DragDropEffects ef = tableControl.DoDragDrop(style.CellValue.ToString(),DragDropEffects.Copy);  
  
            }  
        }  
    }  
}  
  
private void GridGroupingControl1_DragEnter(object sender, DragEventArgs e)  
{  
    if (e.Data.GetDataPresent(DataFormats.Text))  
    {  
        e.Effect = DragDropEffects.Copy;  
    }  
    else  
    {  
        e.Effect = DragDropEffects.None;  
    }  
}  
  
  
  
Form_ TreeViewAdv1  
Code example  
destination_gridGroupingControl1.DragEnter += Destination_gridGroupingControl1_DragEnter;  
destination_gridGroupingControl1.DragDrop += Destination_gridGroupingControl1_DragDrop;  
  
private void Destination_gridGroupingControl1_DragDrop(object sender, DragEventArgse)  
{  
    int rowIndex, colIndex;  
    Syncfusion.Windows.Forms.Grid.Grouping.GridGroupingControl grid = sender asSyncfusion.Windows.Forms.Grid.Grouping.GridGroupingControl;  
    if (grid != null)  
    {  
        grid.TableControl.PointToRowCol(grid.TableControl.PointToClient(new Point(e.X, e.Y)),out rowIndex, out colIndex);  
        if (rowIndex > 0 && colIndex > 0)  
        {  
            GridTableCellStyleInfo style = grid.TableControl.GetTableViewStyleInfo(rowIndex, colIndex);  
            Element element = style.TableCellIdentity.DisplayElement;  
            if (element.Kind == DisplayElementKind.Record)  
            {  
                Record record = element.GetRecord();  
                int fieldIndex =this.destination_gridGroupingControl1.TableDescriptor.ColIndexToField(colIndex);  
                String columnName =this.destination_gridGroupingControl1.TableDescriptor.Columns[fieldIndex].Name;  
                record.SetValue(columnName, e.Data.GetData(DataFormats.Text));  
            }  
        }  
  
    }  
}  
  
private void Destination_gridGroupingControl1_DragEnter(object sender, DragEventArgse)  
{  
    if (e.Data.GetDataPresent(DataFormats.Text))  
    {  
        e.Effect = DragDropEffects.Copy;  
    }  
    else  
    {  
        e.Effect = DragDropEffects.None;  
    }  
}  
  
  
Sample link: GridGroupingControl  
 
Query 2 : I need to move the contents of any cell from GGC   and  source_textBox1  with my mouse from source_gridGroupingControl1 (Form200)  and source_textBox1  to treeViewAdv1 (Form__TreeViewAdv1) 
 
In order to drag and drop TextBox.Text value to TreeViewAdv control, You should enable AllowDrop property and handle DragEnter and DragDrop event in TreeViewAdv. Please make use of below code snippet. 
 
Form_ TreeViewAdv1.cs 
 
 
this.treeViewAdv1.DragEnter += TreeViewAdv1_DragEnter; 
this.treeViewAdv1.DragDrop += new DragEventHandler(treeViewAdv1_DragDrop); 
 
private void TreeViewAdv1_DragEnter(object sender, DragEventArgs e) 
{ 
       e.Effect = DragDropEffects.Copy; 
} 
 
private void treeViewAdv1_DragDrop(object sender, DragEventArgs e) 
{ 
       TreeNodeAdv node = new TreeNodeAdv(); 
       if (e.Data.GetDataPresent(DataFormats.Text)) 
       { 
           Point pt = ((TreeViewAdv)sender).PointToClient(new Point(e.X, e.Y)); 
           TreeNodeAdv dn = ((TreeViewAdv)sender).GetNodeAtPoint(pt); 
           node = new TreeNodeAdv(e.Data.GetData(DataFormats.Text).ToString()); 
           dn.Nodes.Add(node.Clone()); 
           dn.Expand(); 
           node.Remove(); 
      } 
} 
 
 
We have modified your sample as per the requirement which can be downloaded from the below location. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
Senthil 



GP Gregory Pe replied to Senthil Kumaran Rajan August 14, 2018 08:47 PM UTC

Hi Gregory, 
 
Query 1 : I need to move the contents of any cell from GGC   and  source_textBox1  with my mouse from source_gridGroupingControl1 (Form200)  and source_textBox1  to destination_gridGroupingControl1 (Form__TreeViewAdv1) to  dropped line   Columns "drag_and_drop_IN" - to be completed 
 
To DragDrop the GridGroupingControl cell value to other controls, you could use the TableControlMouseDown event to copy the cell value and use DragDop event to get the dropped value the you could set that value to record using SetValue method. Please refer to the below code example,  
  
Form200  
Code example  
this.gridGroupingControl1.TableControlMouseDown += gridGroupingControl1_TableControlMouseDown;  
this.gridGroupingControl1.DragEnter += GridGroupingControl1_DragEnter;  
  
void gridGroupingControl1_TableControlMouseDown(object sender,GridTableControlMouseEventArgs e)  
{  
    GridGroupingControl grid = sender as GridGroupingControl;  
  
    if (grid != null)  
    {  
        GridTableControl tableControl = grid.TableControl;  
        Point pt = new Point(e.Inner.X, e.Inner.Y);  
        int row, col;  
        if (tableControl.PointToRowCol(pt, out row, out col))  
        {  
            GridTableCellStyleInfo style = tableControl.Model[row, col];  
            //checks if the cell in which the MouseDown event is a RecordRowHeaderCell.  
            //If yes, then begins the DragDrop operation.  
            if(style.TableCellIdentity != null && style.TableCellIdentity.DisplayElement.Kind ==DisplayElementKind.Record)  
            {  
                DragDropEffects ef = tableControl.DoDragDrop(style.CellValue.ToString(),DragDropEffects.Copy);  
  
            }  
        }  
    }  
}  
  
private void GridGroupingControl1_DragEnter(object sender, DragEventArgs e)  
{  
    if (e.Data.GetDataPresent(DataFormats.Text))  
    {  
        e.Effect = DragDropEffects.Copy;  
    }  
    else  
    {  
        e.Effect = DragDropEffects.None;  
    }  
}  
  
  
  
Form_ TreeViewAdv1  
Code example  
destination_gridGroupingControl1.DragEnter += Destination_gridGroupingControl1_DragEnter;  
destination_gridGroupingControl1.DragDrop += Destination_gridGroupingControl1_DragDrop;  
  
private void Destination_gridGroupingControl1_DragDrop(object sender, DragEventArgse)  
{  
    int rowIndex, colIndex;  
    Syncfusion.Windows.Forms.Grid.Grouping.GridGroupingControl grid = sender asSyncfusion.Windows.Forms.Grid.Grouping.GridGroupingControl;  
    if (grid != null)  
    {  
        grid.TableControl.PointToRowCol(grid.TableControl.PointToClient(new Point(e.X, e.Y)),out rowIndex, out colIndex);  
        if (rowIndex > 0 && colIndex > 0)  
        {  
            GridTableCellStyleInfo style = grid.TableControl.GetTableViewStyleInfo(rowIndex, colIndex);  
            Element element = style.TableCellIdentity.DisplayElement;  
            if (element.Kind == DisplayElementKind.Record)  
            {  
                Record record = element.GetRecord();  
                int fieldIndex =this.destination_gridGroupingControl1.TableDescriptor.ColIndexToField(colIndex);  
                String columnName =this.destination_gridGroupingControl1.TableDescriptor.Columns[fieldIndex].Name;  
                record.SetValue(columnName, e.Data.GetData(DataFormats.Text));  
            }  
        }  
  
    }  
}  
  
private void Destination_gridGroupingControl1_DragEnter(object sender, DragEventArgse)  
{  
    if (e.Data.GetDataPresent(DataFormats.Text))  
    {  
        e.Effect = DragDropEffects.Copy;  
    }  
    else  
    {  
        e.Effect = DragDropEffects.None;  
    }  
}  
  
  
Sample link: GridGroupingControl  
 
Query 2 : I need to move the contents of any cell from GGC   and  source_textBox1  with my mouse from source_gridGroupingControl1 (Form200)  and source_textBox1  to treeViewAdv1 (Form__TreeViewAdv1) 
 
In order to drag and drop TextBox.Text value to TreeViewAdv control, You should enable AllowDrop property and handle DragEnter and DragDrop event in TreeViewAdv. Please make use of below code snippet. 
 
Form_ TreeViewAdv1.cs 
 
 
this.treeViewAdv1.DragEnter += TreeViewAdv1_DragEnter; 
this.treeViewAdv1.DragDrop += new DragEventHandler(treeViewAdv1_DragDrop); 
 
private void TreeViewAdv1_DragEnter(object sender, DragEventArgs e) 
{ 
       e.Effect = DragDropEffects.Copy; 
} 
 
private void treeViewAdv1_DragDrop(object sender, DragEventArgs e) 
{ 
       TreeNodeAdv node = new TreeNodeAdv(); 
       if (e.Data.GetDataPresent(DataFormats.Text)) 
       { 
           Point pt = ((TreeViewAdv)sender).PointToClient(new Point(e.X, e.Y)); 
           TreeNodeAdv dn = ((TreeViewAdv)sender).GetNodeAtPoint(pt); 
           node = new TreeNodeAdv(e.Data.GetData(DataFormats.Text).ToString()); 
           dn.Nodes.Add(node.Clone()); 
           dn.Expand(); 
           node.Remove(); 
      } 
} 
 
 
We have modified your sample as per the requirement which can be downloaded from the below location. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
Senthil 


Hi Senthil
works great
thank you

Regards, 
Gregory


KR Kannan R Syncfusion Team August 15, 2018 04:22 AM UTC

Hi Gregory 
 
Thank you for your update. Please let us know if you need further assistance.  
 
Regards 
Kannan 


Loader.
Up arrow icon