Drag&drop between 2 txbrowse (NageswaraRao)

Drag&drop between 2 txbrowse (NageswaraRao)

Postby Marc Vanzegbroeck » Sat Oct 25, 2008 6:36 pm

Hi,

I have a problem dragging from 1 txbrows to another.

I have found somewere in this forum a example from NageswaraRao with this code:
Code: Select all  Expand view
STATIC FUNCTION DropOver1( uDropInfo, nRow, nCol, nFlags, oBrw )
   oBrw:lButtonDown( nRow, nCol, nFlags)
   oBrw:lButtonUp(   nRow, nCol, nFlags)
  ...
RETURN NIL


The problem is that this function only select te dropped cell if you drag the same txbrowse. Dragging it to another, the dropper cell is not selected but still the one that was selected before. I allready tried to add
Code: Select all  Expand view
obrw:setfocus()

in the beginning of the function, but it doesn't work.

Is there a solution for this?

Thanks,
Marc
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Postby Antonio Linares » Sun Oct 26, 2008 11:23 pm

Marc,

Here you have Nageswararao example adapted for two xbrowses:

test.prg
Code: Select all  Expand view
#include 'fivewin.ch'

FUNCTION Main()

   LOCAL oWnd, oBrw1, oBrw2, oCur, i, aData := {}

   FOR i := 1 TO 6
      AAdd( aData, { str(i,2), "Description " + Str( i ), Replicate( Chr( 64 + i ), 5 ) } )
   NEXT i

   DEFINE CURSOR oCur DRAG
   DEFINE WINDOW oWnd
   
   oWnd:SetSize( 650, 350 )
   
   oBrw1 := TXBrowse():New( oWnd )
   oBrw1:SetArray( aData )
   oBrw1:CreateFromCode()
   oBrw1:SetSize( 300, 200 )
   //
   oBrw1:oDragCursor := oCur
   oBrw1:bDragBegin  := { |nRow,nCol,nFlags| DragBegin( nRow, nCol, nFlags, oBrw1 ) }
   oBrw1:bDropOver   := { |uDropInfo, nRow, nCol, nFlags| DropOver( uDropInfo, nRow, nCol, nFlags, oBrw1 ) }
   //

   oBrw2 := TXBrowse():New( oWnd )
   oBrw2:SetArray( aData )
   oBrw2:CreateFromCode()
   oBrw2:nLeft = 310
   oBrw2:SetSize( 300, 200 )
   //
   oBrw2:oDragCursor := oCur
   oBrw2:bDragBegin  := { |nRow,nCol,nFlags| DragBegin( nRow, nCol, nFlags, oBrw2 ) }
   oBrw2:bDropOver   := { |uDropInfo, nRow, nCol, nFlags| DropOver( uDropInfo, nRow, nCol, nFlags, oBrw2 ) }

   ACTIVATE WINDOW oWnd
   oCur:End()

RETURN NIL

STATIC FUNCTION DragBegin( nRow, nCol, nFlags, oBrw )

   SetDropInfo( { EVAL( oBrw:SelectedCol():bStrData ), oBrw } )

RETURN NIL

STATIC FUNCTION DropOver( uDropInfo, nRow, nCol, nFlags, oBrw )

   local aPoint := { nRow, nCol }

   if uDropInfo[ 2 ]:hWnd != oBrw:hWnd
      aPoint = ClientToScreen( uDropInfo[ 2 ]:hWnd, aPoint )
      aPoint = ScreenToClient( oBrw:hWnd, aPoint )
      nRow = If( aPoint[ 1 ] > 30000, aPoint[ 1 ] - 65535, aPoint[ 1 ] )
      nCol = If( aPoint[ 2 ] > 30000, aPoint[ 2 ] - 65535, aPoint[ 2 ] )
   endif   

   oBrw:lButtonDown( nRow, nCol, nFlags )
   oBrw:lButtonUp( nRow, nCol, nFlags )

   MsgInfo( uDropInfo[ 1 ] + CRLF + 'dropped on' + CRLF + ;
            EVAL( oBrw:SelectedCol():bStrData ) )

RETURN NIL
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Marc Vanzegbroeck » Mon Oct 27, 2008 7:20 am

Thanks Antonio,

It's working very nice.
The only problem that I have is how can I know the row-number where I drag to? nRow returns the pixels and not the row-number.

If I drag to ex. row 4, and want to replace the 4-field in the database + other fields belonging to that row.

Thanks,
Marc
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Postby Antonio Linares » Mon Oct 27, 2008 8:47 am

Marc,

When you drop on the target xbrowse, the target row is automatically selected, so you can directly update the fields as you are already in the right record.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Marc Vanzegbroeck » Mon Oct 27, 2008 9:44 am

Antonio,

The problem is that also other fields that are not displayed in the xbrowse should be updated. The browse only show the titel of the item. Doubleclicking the cell in the browse shows the other fields related to the item. So I need to know to what row it is dragged to, so I can olso update those fields.

Regards,
Marc
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Postby Antonio Linares » Mon Oct 27, 2008 11:17 am

Marc,

RecNo() for a DBF or oBrw:nArrayAt for an Array,

or oBrw:nRowSel if you want a relative position
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Marc Vanzegbroeck » Mon Oct 27, 2008 12:49 pm

Antonio,

For the row I already used recno(). The only problem was the Column.
With you suggestion 'oBrw:nRowSel', I now found 'oBrw:nColSel'.

That is exactly what I needed.

Thanks,
Marc
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Postby nageswaragunupudi » Sat Nov 08, 2008 10:25 pm

A small improvement to the above code.

Earlier I used the following code to position the cursor at the mouse dropover coordinates.

Code: Select all  Expand view
   oBrw:lButtonDown( nRow, nCol, nFlags )
   oBrw:lButtonUp( nRow, nCol, nFlags )


But the behavior was not satisfactory under all circumstances. Now I am using the following code. Please try this instead of the above code.

Code: Select all  Expand view
   if oBrw:SetPos( nRow, nCol, .t. ) // nRow, nCol in pixels
      // browse cursor is repositioned at the
      // dropped coordinates
     
     < .... our code to deal with the drop ....>

   else
     // drop is not within valid browse area
     // not a valid drop
     // ignore the drop
   endif
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby Marc Vanzegbroeck » Tue Nov 11, 2008 12:50 pm

Thanks for the info, but I'm still using FWH7.10 and oBrw:SetPos() is not implemented in that release.
I will use it after upgrading my FWH-version.

Regards,
Marc
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 60 guests