[Solved] drag and drop treeview in stringgrid ? lazarus / 21-General ---------------------------------------------------------------------- majid.ebru · 2024-06-09 08:33 Hi please help and guide me ? how can i drag item of treeview in stringgrid and detected that ? thank you ---------------------------------------------------------------------- bobby100 · 2024-06-09 09:07 I will try to help you and describe how I would do it. You would need a global variable where you would put your data that you want to drag & drop. Just for the sake of the example, let say we want to transport just a string, so I will name this variable MyTransportedString - declare it in the VAR section of the unit/form, and initialize it in the OnCreate of the Form1. For more complex data, you can use a Record. Now, you need to process 3 procedures: - TreeView1.StartDrag - StringGrid1.DragOver - StringGrid1.DragDrop The StartDrag of the TreeView need to put the string in MyTransportedString: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.TreeView1StartDrag(Sender: TObject; var DragObject: TDragObject);begin  //you need to check for errors here  //like checking if a node is selected at all (user can initiate drag operation even from blank space outside the nodes)  //and proceed just if the user have selected a valid node    //after all the checks, copy the data from the node into our variable  MyTransportedString := TreeView1...Node...Text  //sorry, just pseudocode as I do not know TreeViewend; Now, you need to define from which components your StringGrid will accept the drag&drop Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.StringGrid1DragOver(Sender, Source: TObject; X, Y: integer;  State: TDragState; var Accept: boolean);begin  if Source = TreeView1 then Accept := True  else Accept := False;end; Now, process the drop on the StringGrid: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.StringGrid1DragDrop(Sender, Source: TObject; X, Y: integer);var  DestCol, DestRow: integer;begin  StringGrid1.MouseToCell(X, Y, DestCol, DestRow);  //here do some basic error check, like not to accept the drop if the DestCol or DestRow are zero (fixed cols/rows) etc.  //if everything is OK then proceed  if (DestCol > 0) and (DestRow > 0) then    StringGrid1.Cells[DestCol, DestRow] := MyTransportedString;end; Do not forget to set DragMode for both TreeView and StringGrid to dmAutomatic in Properties ---------------------------------------------------------------------- majid.ebru · 2024-06-09 09:51 @bobby100   thank you ---------------------------------------------------------------------- bobby100 · 2024-06-09 10:02 I have added some more comments to the code, please take a look. Do a proper error checking, it is very important. I am working with ListBoxes, and most of the errors were about IndexOutOfBounds because user can start drag even if there was no item selected in the source ListBox (dragging from the blank space or from an unselected item). ---------------------------------------------------------------------- majid.ebru · 2024-06-10 08:20 thank you i can't select true node then i don't use this your code : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.TreeView1StartDrag(Sender: TObject; var DragObject: TDragObject);begin  //you need to check for errors here  //like checking if a node is selected at all (user can initiate drag operation even from blank space outside the nodes)  //and proceed just if the user have selected a valid node   //after all the checks, copy the data from the node into our variable  MyTransportedString := TreeView1...Node...Text  //sorry, just pseudocode as I do not know TreeViewend; ---------------------------------------------------------------------- bobby100 · 2024-06-10 14:49 I am afraid that I do not understand your message.