Advanced - TableLayoutPanel Drag and Drop

Posted 18 January 2013 - 07:13 PM

Does anyone know if it's possible to set up drag and drop functionality to copy all rows in one tablelayoutpanel to another, when the rows in the first tablelayoutpanel were all created programmatically with rowstyles from a datasource (VB.Net)?? If not, is there a way to copy all the text from the first tablelayoutpanel to the second one with a button?

Part of the problem is that the cells with text in the tablelayoutpanels, are created programmatically from a database, which is working fine, but I can't figure out how to copy the cells that are created:

Re: Advanced - TableLayoutPanel Drag and Drop

Posted 19 January 2013 - 06:39 AM

Please edit your post or, if necessary, copy all to a new post, wrapping your code in code tags - it's very hard to read. It tells you how to do this directly in the area where you are typing your post! Preview your post a few times before posting it.

Make sure the AllowDrop property of the second control is set to True;
Use a MessageBox, or set the text of a label, to check that the second control has recognised the drop.

Re: Advanced - TableLayoutPanel Drag and Drop

Posted 19 January 2013 - 06:58 PM

Quote

Part of the problem is that the cells with text in the tablelayoutpanels, are created programmatically from a database, which is working fine, but I can't figure out how to copy the cells that are created

I don't know what controls your panel contains, or how data from a database has been included, but a TableLayoutPanel has a Controls collection, which I assume you would need to loop (navigate) through to copy data individually.

It is possible to clone the panel (using the ICloneable interface), replacing the 2nd panel, but I'm not sure how this would work with data-sources attached to controls, or even text in textboxes.

Just speculating.. I suppose it would be possible to initially have two versions of the same panel, with one hidden and mirroring and data-changes between them. Then remove the dropped-on panel and replace its location with the hidden version. This sounds a little messy to me.

Re: Advanced - TableLayoutPanel Drag and Drop

Posted 19 January 2013 - 07:09 PM

Actually, to be honest, it sounds strange to me. A TableLayoutPanel is just that: a panel, a container. If you wanted to drag something shouldn't it be one of the controls that it contains, such as a TextBox for its content(?).

[In Microsoft Access, when I drag a form onto another form it does copy it, but its only copying an empty shell (effectively, creating a new instance of the form) whose record-source happens to already be specified.]

Re: Advanced - TableLayoutPanel Drag and Drop

Posted 19 January 2013 - 07:11 PM

Thanks for that suggestion. I had thought of that, but the end objective is to be able to COPY all the text in the cells of the TableLayoutPanel, which are created by RichTextBoxes. Your idea would work if it was simply copying the cells, but the text can be revised, so select all to copy, or drag and drop is preferable. ....still trying, but I am relatively new to VB. If I get this resolved, I will post the code. Thanks for your support.

Re: Advanced - TableLayoutPanel Drag and Drop

Posted 02 February 2013 - 06:07 AM

It turns out that I was wrong about how to accomplish this drag and drop for dynamically created RichTextBoxes in a TableLayoutPanel. I didn't need any of the standard drag and drop code, all I needed to do was to enable dragging and dropping in the code of the TableLayoutPanel.

The only problem now is that there is no way to control the AllowedEffects (Copy, Move, None), so the drag and drop only Moves the text. Can you help me find a way to COPY only, so the text doesn't MOVE from the original RichTextBox?