cancel
Showing results for 
Search instead for 
Did you mean: 

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

vlad1
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

vlad1
Participant
0 Kudos

I see, so it's impossible altogether, bummer It does make me think though that it should be really easy to introduce, surely somewhere at native PB code there are ways to grab whatever is black-selected? I can't believe that no-one ever suggested this before?

Anyway, in the meantime, any suggestions, or even better, code examples (I'm incredibly pressed for time) how to introduce the quick copy-paste into Excel or Notepad from a grid browser datawindow where 90% of the columns are not accessible?

My first thought is to switch on the Row Selection service which allows a multiple row selection, then on copy() event save the this.Object.Data.Selected to local datastore, and then datastore.SaveAs("blah.txt", Clipboard, false), but this is slightly cumbersome - I would like to be able to copy-paste one single cell from the grid datawindow, and not necessarilly copy-paste the whole row. If the column is accessible, that is easy, but if it is protected and tab-order = 0, I'd still like to be able to do it somehow?

Thanks

Former Member
0 Kudos

Hi Vlad;

  OK ... with some more great Canadian coffee and I was able to McGyver it ... LOL! 

FYI ... My Test:

Note: The prototype code I worked up for this test is in PB 12.1. Can you use that PB version? If so, I can just post the work-space solution it here.

Regards ... Chris

vlad1
Participant
0 Kudos

Wow, I am currently googling superlatives to describe how awesome this is!

Alas, no, I am using PB 11.5.1, but I am dearly hoping at the moment that your code will work just the same?

/on his knees, muttering prayers

Former Member
0 Kudos

Hi Vlad;

  I exported the objects from my test PB Classic work-space in v12.1 into a ZIP file. I think that they should import into PB 11.x - except maybe for the DWO. You can just recreate any Grid DWO from the example DB that comes with PB though and this should work as the columns are not hard coded.

  The main processing is all done in the Window class - so that is the important area to look at. I would recommend encapsulating this approach in a base DW ancestor though for better adherence to OO principles. Also, the prototype code only handles "string" data types - so it needs to be made a little more robust in that area. However, I hope this approach / concept will get you started. 

Regards ... Chris

vlad1
Participant
0 Kudos

Fantastic Chris. Doubt I will have time for it today, but I can't wait to test this out! Thanks so much!

Answers (3)

Answers (3)

Former Member
0 Kudos

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

vlad1
Participant
0 Kudos

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

Former Member
0 Kudos

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

intli_rc
stringls_selected_data

ls_selected_data = This.Object.Datawindow.Selected.Data

::Clipboard(ls_selected_data)

Former Member
0 Kudos

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

vlad1
Participant
0 Kudos

Yes I did, but no matter what I do, ls_data is empty string. But according to Chris, the Mouse Selection is not a true SELECT for the datawindow columns and rows, so that's probably why.

Former Member
0 Kudos

Hi Mike;

  I though about this approach as well but, you do not know a) row; b) column name c) its usage; d) its data type; e) the order the datum was selected, etc. If that is not an issue - then this approach would work as a good "as is" data dump/copy.

Regards ... Chris

Former Member
0 Kudos

vlad,
the ls_data is empty because of something else.  are you looking at the data PRIOR to your event call?

it will have data in it if you have mouse select enabled for a grid datawindow.

I suppose is possible that your version of PB has a bug in it.

Chris, if you are copying the data to something like excel, then those things typically won't matter.

The user would expect it to copy over exactly as the black select displays.  Powerbuilder does do this even if the user had moved the columns.  appeon web has a bug that copies the data in the column order of the original datawindow instead of the displayed order.

if you copy FROM excel, it copies data just like powerbuilder does it (tab delimited strings).  the selection process works much nicer in excel however.

Former Member
0 Kudos

  I have had this conversation with Sybase way back when and Appeon recently ... pointing out half-baked features like this in the DWO & Painter that should have been there long ago. Its this missing "polish" of features (IMHO) that also contributed to the DW.Net product's demise as well. If you are going to market the DW as a product or even "the feature" within PB .. it better be freak'in awesome as that's what today's developer community is expecting.  

  Another simple example of DW "polish" would be to allow a bar graph to have totals on each bar, maybe add a GetItemAny ( ) method, set the graph colours in the DW painter, allow expressions on all properties, bullet mouse scrolling (middle mouse button   ), etc.

Former Member
0 Kudos

Hi Mike;

   Although this works, the drawback with this approach is the values the user sees in the DW display area vs what is in the DW's primary buffer. For example: where a column uses an EditMask code table, DDDW, etc or a Display mask. The  "This.Object.Datawindow.Selected.Data" approach only gets you the raw data whereas I would use a LookupDisplay ( ) method instead in my approach or a String (GetItemXxxx, "<mask") when transferring the datum to Excel.

   As an example ... in a State/Province column your DBMS and thus DW primary buffer may have the value "CA" however, the user sees "California" because of the presence of a DDDW. The "This.Object.Datawindow.Selected.Data" will transfer "CA" to Excel whereas my approach would transfer "California"  (ie: dw1.Describe("Evaluate('LookUpDisplay(state_cd', 5)")).

Food for thought.

Regards ... Chris

Former Member
0 Kudos

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.