FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Drag&drop between 2 txbrowse (NageswaraRao)
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Drag&drop between 2 txbrowse (NageswaraRao)
Posted: Sat Oct 25, 2008 06: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:
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
obrw:setfocus()

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

Is there a solution for this?

Thanks,
Marc
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Drag&drop between 2 txbrowse (NageswaraRao)
Posted: Sun Oct 26, 2008 11:23 PM
Marc,

Here you have Nageswararao example adapted for two xbrowses:

test.prg
#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
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Drag&drop between 2 txbrowse (NageswaraRao)
Posted: Mon Oct 27, 2008 07: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

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Drag&drop between 2 txbrowse (NageswaraRao)
Posted: Mon Oct 27, 2008 08: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
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Drag&drop between 2 txbrowse (NageswaraRao)
Posted: Mon Oct 27, 2008 09: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

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Drag&drop between 2 txbrowse (NageswaraRao)
Posted: 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
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Drag&drop between 2 txbrowse (NageswaraRao)
Posted: 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

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Drag&drop between 2 txbrowse (NageswaraRao)
Posted: 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.

   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.

   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
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Drag&amp;drop between 2 txbrowse (NageswaraRao)
Posted: 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

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite

Continue the discussion