ListControls icon indicating copy to clipboard operation
ListControls copied to clipboard

Copy Paste

Open holgerschochwitz opened this issue 8 years ago • 3 comments

Hi, can you insert a copyRow and pasteRow function? Or can you explain me, how can i use Copy and Paste in the control.

Thank you

Holger

holgerschochwitz avatar Jan 08 '18 13:01 holgerschochwitz

I assume you're referring to the DataList control. Copying and pasting from the clipboard is rather application specific so it's probably best handled by the form on which the data list control resides. I'd suggest perhaps adding a KeyDown or KeyPress event for the data list and handing the common copy/paste key combinations.

The SelectionStart and SelectionEnd properties on the DataList control can be used to get the range of selected row headers. You can then use that range to get the item or items to copy to the clipboard. Pasting would be a matter of getting the information from the clipboard and appending clones of those items to the data source. Below is a rough idea of the process for copying:

int selStart = dataList.SelectionStart, selEnd = dataList.SelectionEnd;

if(selStart == -1)
    selStart = selEnd = dataList.CurrentRow;

dataList.CommitChanges();

while(selStart <= selEnd)
{
    object row = dataList.ListManager.List[selStart];

    ... Make a copy, add it to an array etc. ...

    selStart++;
}

... Copy the array etc. to the clipboard ...

EWSoftware avatar Jan 08 '18 19:01 EWSoftware

Can i create a new row in the datalList without a refresh? I get an error when I try this:

`Dim sourceRow As DataRowView = newDR.ListManager.List.Item(1)

newDR.ListManager.List.Insert(newDR.CurrentRow, sourceRow.Row.ItemArray.Clone) `

holgerschochwitz avatar Jan 09 '18 15:01 holgerschochwitz

Sorry, I somehow managed to miss this one. You didn't list what the error was but I assume that should work. An alternative as shown in the demo code is to add the row directly to the table.

EWSoftware avatar Nov 09 '20 21:11 EWSoftware