Copy and Paste Grid cell data

I have a grid control in my app.

I’d like to be able to copy cells from Excel and paste them into my grid.

And vice versa… copy from my grid and paste into Excel.

I had some old code that worked for this in Visual Basic but my conversion of that code isn’t working right.
Just wondering if someone already has some code for this.


if it is a ListBox

make 3 Properties

myrow As Integer
mycolumn As Integer
mycelltext As String


myrow = row mycolumn = column


if me.ListCount > 0 then if me.Selected(myrow) = true Then mycelltext = me.Cell(myrow, mycolumn) end if end if

you can use mycelltext for clipboard


dim c as new clipboard c.text = mycelltext


dim c as new clipboard me.Cell(myrow, mycolumn) = c.text

How do I detect Ctrl-C or Copy and Ctrl-V paste?

In VB it was a native keyboard code passed to KeyDown.

I am reading a couple of posts that Xojo doesn’t have that.

It is the StyleGrid control not a listbox.

Subclass the control and implement a menu handler for EditCopy and EditPaste.

do not invest too much on stylegrid, it’s not been updated for years …

I know I have already been burned badly. Thinking of switching to pi dog DataView.

Ok I know this is a dumb question but how does the control have a menu handler? When I try to create a new menu handler it is not tied to a control but just in the list of menu handlers for the window or the app.

if you subclass the control, then you can have a menuhandler that belongs to the control, and not the window.

What if you alreayd have an EditCopy at the Window level? If you add EditCopy to the grid subsclass… it will call the grid one if the grid is selected???

Yes. The hierarchy is control - window - app.

if you return true from the menuhandler, it means your control has handled all the work and nothing more will be executed
if you return false, the work goes to the window, and then to the app.

Thanks guys. This helps. I will give it a shot.

I just learned this from Norman
DO NOT add EDITCOPY (or any of the other EDITxxx menu items) to your own menu class (popup or otherwise)