Hi all, I have interesting question.
Let's set some text to grid cell and then copy:
Let's paste copied string to Word and enable showing of special characters:
You can see that cells are separated by some special symbols. But if I copy from old grid for VB 6 separator is tab symbol:
How can I set tab as a separator in Windows Forms Grid? If I should implement custom parsing how can I get copy string after calling grid.PerformAction(UltraGridAction.Copy)?
Any help would be appreciate.
Hi Maksim,
Thank you for posting in our forums.
What you can do in your case is to handle the BeforeMultiCellOpearation event of the grid. In it asynchronously get the text from the clipboard and replace the empty characters with a tab character and set it back as the clipboard text. This way when you paste the text into word it will have tabs as the separators.
I have attached a small sample which demonstrates this suggestion.
Let me know if you have any additional questions.
Thank you too for quite quick reply. Everything is clear for me in your attached project. Awesome.
I have one more question, may be you are able to ask me :)
I have WinForms context menu where right after clicking on Copy button I call grid.PerformAction(UltraGridAction.Copy) method and I expect that anyone from BeforeCellUpdate or AfterCellUpdate will be called. But this events are raised only when I press Ctrl+C button, PerformAction() does not lead to excitation of these both events. Any ideas? :)
Thank you for the reply.
I tried to reproduce this and I can’t get the After/BeforeCellUpdate events to fire when I use Control+C or when I use the PerformAction method with Copy parameter. It seems very strange to me that the event will fire when you perform the Copy operation, since nothing changes in the cells. If you want to know when the user has copied some of the grid’s cell, the best place would be BeforeMultiCellOperation event, where you can also access the cells, which were copied by using the Cells parameter of the event arguments.
Still I attached a modified version of the sample I sent you, which I used to test this. If you are able to modify it in order to reproduce the behavior that you have reported, I will be glad to research it further for you.
Please let me know if you have any additional questions.
Your example is a good way, but if my cell contain spaces developer has to implement a lot of custom logic to parse clipboard. This fact complicates quite simple task :(
I have modified my sample in order to work properly when the cells contain spaces. It now iterates through the copied cells and concatenates their text with a tab or new line separators depending if the cell is on the same row as the previous one or not.