Posted 21 April 2022, 4:08 am EST
Hi,
I’m wondering if it’s possible to use Ctrl+C to copy a selected area of the Grid to insert it with Ctrl+V in a Text-Document.
If it’s possible, a Code in VB.net would be great.
Thanks and best regards
Stephan
Forums Home / ComponentOne / WinForms Edition
Posted by: s.wortmann on 21 April 2022, 4:08 am EST
Posted 21 April 2022, 4:08 am EST
Hi,
I’m wondering if it’s possible to use Ctrl+C to copy a selected area of the Grid to insert it with Ctrl+V in a Text-Document.
If it’s possible, a Code in VB.net would be great.
Thanks and best regards
Stephan
Posted 21 April 2022, 8:14 am EST
Hi Stephan,
You can handle the KeyDown event of the C1TrueDBGrid to check if the Ctrl+C is pressed and suppress the keypress to manually handle the Copy. To copy the data from the selected cells of the C1TrueDBGrid, you can iterate through the selected cells and copy their text into a string variable. Then you can use the Clipboard.SetText() method to set the copied string in the clipboard so that it can be pasted into other programs. Kindly refer to the attached sample showing the same.
Best Regards,
Kartik
Posted 27 April 2022, 9:57 am EST
Hi Kartik,
your example works fine, however the cell-contents of hidden columns are still copied to the clipboard.
Do you have any idea how to prevent this?
Best regards
Stephan
Posted 27 April 2022, 11:59 pm EST
Hi Stephan,
To skip the hidden columns, you can add a check for the hidden columns in the CopyDataToClipboard method by using the C1DisplayColumn.Visible property. Please refer to the updated sample.
Kind Regards,
Kartik
Posted 3 May 2022, 8:24 am EST
Hi Kartik.
Thank you very much for your renewed help and the example.
Everything works as it should.
Best regards.
Stephan