Best way to copy-paste data from "Mouse selection" grid DW?

Hi, I've got a grid datawindow looking like:

Where apart from the default blue highlighted line of the current row, I have enabled "Mouse Selection" across the fields. I am trying to find the best way to move the selected data cells, if possible all the selected text, but if not, at least one line / one cell, selected with a mouse like on the screenshot, to Clipboard, so it can be copy-pasted into Excel or similar.

I'm trying to capture the data with

ls_selected_data = (this.Describe("DataWindow.Selected.Data"))

this.event ue_setclipboard(ls_selected_data)


(that event simply does Clipboard(passed parameter) )

but not matter what I try, ls_selected_data always remains an empty string, ""

I'm sure I'm missing something really simple to get that selected data, but I cannot see what exactly? For the record, all columns on the datawindow except first and last are not updateble and have a tab order set to 0, to make them inaccessible to users.

Ideally, I would like just to right-click and be able to use native "Copy" facility from the right-click pop-up window. I have already made the pop-up show option "Copy" by extending pfc_prermbmenu() with

am_dw.m_table.m_copy.enabled = true

Cheers for any insight

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 22, 2015 at 11:50 AM

    Hi Vlad;

      Unfortunately, the DW does not support this. When you set mouse selection, you are really just allowing the user to drag & drop the columns to change their display order in the grid DW.

      This would be a great enhancement idea though!

    I wonder though if we could McGyver it? I'll have to have some more coffee & get back to you on that one.  😉

    Regards ... Chris

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 22, 2015 at 02:36 PM

    that describe will return the selected text in the format needed to put it into the clipboard.

    the datawindow must be grid for it to work.

    did you run through in debugger mode to see whether it is putting the selected text in there?

    string ls_data

    ldw_control.accepttext( )

    ls_data = ldw_control.Object.Datawindow.Selected.Data

    if len(ls_data) > 0 then

         clipboard(ls_data )

    else

         ldw_control.Copy()

    end if

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      yes, the use of raw vs formatted data in the copy (as well in the saveas) is something to consider.

      it would be helpful to have options for these (raw vs decoded?).  sometime you will want to have the raw data and sometime not.  users will want to decide.

      In any case, the original question that vlad asked is what he is doing that prevents the copy from working.  It appears that his problem could be solved by just putting the selected data directly into the clipboard rather than trying to send it to a custom event.  I really don't think that PB 11.5 had a bug that prevented the copy from working.

  • avatar image
    Former Member
    Nov 13, 2015 at 01:05 AM

    Hi,

    I think this is what you were really asking for...

    If you query datawindow.selected using describe you will find the 'black' selected areas. For example "1/11/firstname/lastname/address" if the user has mouse selected those three columns for rows 1 to 11.

    In this example, all columns are of type string.

    string ls4Clipboard, lsSelected
    integer lidx
    long lRow, lRowStart , lRowFinish
    string lCol[]
    
    
    lsSelected = dw_sheet.Describe ( 'datawindow.selected' )
    
    
    if pos ( lsSelected , '/' ) = 0 then return 0
    if pos ( lsSelected , ';' ) > 0 then
      lsSelected = left ( lsSelected , pos ( lsSelected , ';' )  - 1)
    end if
    
    
    lRowStart = long( left ( lsSelected , pos ( lsSelected , '/' ) - 1 ))
    lsSelected = mid ( lsSelected , pos ( lsSelected , '/' )  + 1 )
    lRowFinish = long( left ( lsSelected , pos ( lsSelected , '/' ) - 1 ))
    lsSelected = mid ( lsSelected , pos ( lsSelected , '/' )  + 1 )
    
    
    DO WHILE pos ( lsSelected , '/' ) > 0 
      lidx++
      lCol[lidx] = left ( lsSelected , pos ( lsSelected , '/' ) - 1 )
      lsSelected = mid ( lsSelected , pos ( lsSelected , '/' )  + 1 )
    LOOP
    if lsSelected <> '' then
      lidx++
      lCol[lidx] = lsSelected 
    end if
    
    
    FOR lRow = lRowStart to lRowFinish
      for lidx = 1 to UpperBound ( lCol[] )
      if not IsNull ( dw_sheet.GetItemString ( lRow , lcol[lidx] )) then 
      ls4ClipBoard += dw_sheet.GetItemString ( lRow , lcol[lidx] )
      end if
      if lidx < UpperBound ( lCol[] ) then ls4Clipboard +='~t'
      next
      ls4ClipBoard += '~r~n'
    NEXT
    
    
    ClipBoard ( ls4Clipboard )
    
    
    return 1
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    You will notice that if there are two sets of rows/columns that are mouse selected they are separated by a semicolon: 3/5/col1/col2;7/8/col1/col2/col3

    In my script I ignore second selection.

    Hope this helps

    Lars

    Add comment
    10|10000 characters needed characters exceeded

    • Thanks very much Lars,

      This was in the meantime identified as "not so quite insanely important" as it was when I started the thread, but the moment I get the urgent project off of my back I will try both yours and Chris' solutions.

      Cheers

  • avatar image
    Former Member
    Oct 22, 2015 at 10:20 PM

    i use the mouse selection in a gridstyle DW and simply code this in the rbuttondown event

    int li_rc string ls_selected_data

    ls_selected_data = This.Object.Datawindow.Selected.Data

    ::Clipboard(ls_selected_data)

    Add comment
    10|10000 characters needed characters exceeded

Skip to Content