Drag grid item to another grid

Utilities like DBU, Make, IDE written in HMG/ used to create HMG based applications

Moderator: Rathinagiri

User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Drag grid item to another grid

Post by esgici »

mol wrote: Fri Jan 11, 2019 9:45 pm We have no leader now, who will create new versions.
It's really sad.

Thanks Edward for your great work!
like
like
Like.JPG (8.71 KiB) Viewed 7355 times

Except leaderless status :(

We have a forum builder admin, it isn't :?
Viva INTERNATIONAL HMG :D
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Drag grid item to another grid

Post by mol »

There is a problem with <ParentWindowName>.<TreeControlName>.GetPathValue ( nValue ) --> anPathValue | NIL get property.

When I call it, runtime error is generated:

Code: Select all

Error BASE/1132 Błąd zakresu tablicy: Nieprawidłowa liczba argumentów - Error array range - Incorrect number of parameters
Called from OBSLBLEDU(758) 
Called from (b)MAIN(239) 
Called from TREEITEMGETHANDLE(442) 
Called from TREEITEMGETPATHVALUE(598) 
Called from _TREE_GETPROPERTY(10062) 
Called from GETPROPERTY(8361) 
Called from line: MsgDebug(this.Value, MainForm.Tree.GetPathValue(this.Value))

edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Drag grid item to another grid

Post by edk »

mol wrote: Tue Jan 15, 2019 3:03 pm There is a problem with <ParentWindowName>.<TreeControlName>.GetPathValue ( nValue ) --> anPathValue | NIL get property.

When I call it, runtime error is generated:

Code: Select all

Error BASE/1132 Błąd zakresu tablicy: Nieprawidłowa liczba argumentów - Error array range - Incorrect number of parameters
Called from OBSLBLEDU(758) 
Called from (b)MAIN(239) 
Called from TREEITEMGETHANDLE(442) 
Called from TREEITEMGETPATHVALUE(598) 
Called from _TREE_GETPROPERTY(10062) 
Called from GETPROPERTY(8361) 
Called from line: MsgDebug(this.Value, MainForm.Tree.GetPathValue(this.Value))

I can't reproduce it. :( Get path by DblClick on node/item

Code: Select all

#include "hmg.ch"

Function main()

EnableDragAndDrop()

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 700 ;
		HEIGHT 500 ;
		TITLE 'TreeView Simple Sample Drag And Drop' ;
		MAIN 

		@ 30,10 LABEL Label_2 VALUE "Tree #1." AUTOSIZE
	
		DEFINE TREE Tree_1 ;
				AT 50,10 ;
				WIDTH 200 HEIGHT 400 ;
				VALUE 227 ;
				ON GOTFOCUS Drag_Tree1() ;
				ON CHANGE Form_1.Title:='Tree #1, Item # '+hb_valtostr(Form_1.tree_1.Value)+" , ItemName " +Form_1.tree_1.Item(Form_1.Tree_1.Value) ;
	               ON DBLCLICK MsgDebug (Form_1.Tree_1.Value, Form_1.Tree_1.GetPathValue (Form_1.Tree_1.Value)) ;
				ITEMIDS

			NODE 'Item 1' ID 1 
				TREEITEM 'Item 1.1' ID 11
				TREEITEM 'Item 1.2' ID 12
				TREEITEM 'Item 1.3' ID 13
			END NODE

			NODE 'Item 2' ID 2

				TREEITEM 'Item 2.1' ID 21

				NODE 'Item 2.2' ID 22
					TREEITEM 'Item 2.2.1' ID 221
					TREEITEM 'Item 2.2.2' ID 222
					TREEITEM 'Item 2.2.3' ID 223
					TREEITEM 'Item 2.2.4' ID 224
					TREEITEM 'Item 2.2.5' ID 225
					TREEITEM 'Item 2.2.6' ID 226
					TREEITEM 'Item 2.2.7' ID 227
					TREEITEM 'Item 2.2.8' ID 228
				END NODE

				TREEITEM 'Item 2.3' ID 23

			END NODE

			NODE 'Item 3' ID 3
				NODE 'Item 3.1' ID 31
					TREEITEM 'Item 3.1.1' ID 311
					NODE 'Item 3.1.2' ID 312
						TREEITEM 'Item 3.1.2.1' ID 3121
						TREEITEM 'Item 3.1.2.2' ID 3122
					END NODE
					TREEITEM 'Item 3.1.3' ID 313
				END NODE				
				
				TREEITEM 'Item 3.2' ID 32

				NODE 'Item 3.3' ID 33
					TREEITEM 'Item 3.3.1' ID 331
					TREEITEM 'Item 3.3.2' ID 332
				END NODE

			END NODE

		END TREE

	END WINDOW
	
	MsgInfo( "Do tree items use IDs? " + hb_valToStr( _IsTreeItemIDs ( 'Tree_1', 'Form_1' ) ))

	ACTIVATE WINDOW Form_1

Return




***********************************
Function Drag_Tree1()
Local cDragFName := HMG_DaD_Drag_Window()
Local cDragCName := HMG_DaD_Drag_Control()
Local cDropFName := HMG_DaD_Drop_Window()
Local cDropCName := HMG_DaD_Drop_Control()
Local nDragTreeValue := HMG_DaD_DragTreeValue()
Local nDropTreeValue := HMG_DaD_DropTreeValue()
Local lIsDraggedWithRightButton := HMG_Is_RButtonDaD()
Local lIsDraggedWithShiftButton := HMG_Is_ShiftDaD()

IF HMG_Is_DaD()
	HMG_Release_DaD()
	DO CASE
		CASE cDragFName == cDropFName .AND. cDragFName == 'Form_1' .AND. cDragCName == cDropCName .AND. cDragCName == 'Tree_1' .AND. nDragTreeValue <> nDropTreeValue
			Tree_UpDate ( cDragFName, cDragCName, nDragTreeValue, cDropCName, cDropFName, nDropTreeValue, .F. /* no copying at IDs -> you have to send some new iID some way ?!? */, !lIsDraggedWithShiftButton )
	
		ENDCASE
ENDIF

RETURN
*************************************************************************

FUNCTION Tree_UpDate ( cDragFName, cDragCName, nDragTreeValue, cDropCName, cDropFName, nDropTreeValue, lCopy, lAdd )
Local aDragItems := _GetTreeItemStru( cDragFName, cDragCName, nDragTreeValue )

//Notice: Version for tree IDs ONLY

IF nDropTreeValue == 0 .AND. !MsgYesNo("Do you want to add an item as Root?", "Dropped in an empty area.", .T.)
	RETURN Nil
ENDIF

IF !EMPTY ( aDragItems )

	DoMethod (cDragFName, cDragCName, "DisableUpdate")
	DoMethod (cDropFName, cDropCName, "DisableUpdate")	

	//remove first to prevent duplicate id from appearing 
	DoMethod (cDragFName, cDragCName, "DeleteItem", nDragTreeValue)

	IF lAdd		//add item
		AEVAL ( aDragItems, { |x| IF ( x[3] == 0, ;
									DoMethod (cDropFName, cDropCName, "AddItem", x[2] , nDropTreeValue /* add on the drop position */, x[1] /* original id */ ) , ;
									DoMethod (cDropFName, cDropCName, "AddItem", x[2] ,  x[3] /* add to the parent position */  , x[1] /* original id */ ) ) } )
									
	ELSE			//insert
		_InsertItem ( cDropCName, cDropFName, aDragItems[1][2] , nDropTreeValue , aDragItems[1][1] /* original id */)
		hb_ADel( aDragItems, 1, .T. )
		AEVAL ( aDragItems, { |x| DoMethod (cDropFName, cDropCName, "AddItem", x[2] , x[3] /* add to the parent position */ , x[1] /* original id */ )  } )
	ENDIF

	DoMethod (cDropFName, cDropCName, "SetDefaultAllNodeFlag")
	
	DoMethod (cDragFName, cDragCName, "EnableUpdate")
	DoMethod (cDropFName, cDropCName, "EnableUpdate")			
		
ENDIF
RETURN 

*************************************************
FUNCTION _GetTreeItemStru( cFormName, cTreeName, nTreeValue )
Local ix := 0
Local aTreeStru := {}, aChild
Local nParent := 0, nItem := 1
IF nTreeValue = 0 //New root
	nTreeValue := 1
ENDIF

IF IsControlDefined ( &cTreeName, &cFormName )
	
	ix := GetControlIndex (cTreeName , cFormName )

	AADD (aTreeStru, { nTreeValue, GetProperty (cFormName, cTreeName, "Item", nTreeValue), nParent } )
	Do While nItem <= LEN ( aTreeStru )
		nParent := aTreeStru [nItem] [1]
		aChild := GetProperty ( cFormName, cTreeName, "ChildValue", nParent )
		nItem ++
		IF hb_isArray ( aChild )
			AEVAL (aChild, { |x| AADD( aTreeStru, { x, GetProperty (cFormName, cTreeName, "Item", x), nParent } ) } )
		ENDIF
	EndDo
ENDIF

IF _IsTreeItemIDs ( cTreeName, cFormName ) .AND. ix > 0
	ASORT ( aTreeStru, , , { |x, y| ascan ( _HMG_SYSDATA [ 25 ] [ix] , x[1] ) < ascan ( _HMG_SYSDATA [ 25 ] [ix] , y[1] ) } )
ELSE
	ASORT ( aTreeStru, , , { |x, y| x[1] < y[1] } )
ENDIF

//*** Structure of aTreeStru***************
//* { { nItem, cItemText, nParentItem } , ... }
//*****************************************

Return aTreeStru
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: Drag grid item to another grid

Post by jairpinho »

edk wrote: Sat Dec 16, 2017 10:10 pm Next version.
Support for dragging GRID column headers has been added.

Due to the ON HEADCLICK event handler, dragging is possible with the right mouse button only.

Within the same Grid, dragging the header changes the order of the columns.

Dragging a column header from GRID Form_1 to Grid Form_2 or Form_3 adds a new column.
By the way, I found a bug in the operation of the AddColumnEx method.
If we add a new column between existing ones, after inserting the column, the neighbor column's caption also changes.

You can test this eg in \SAMPLES\Controls\Grid\GRID_40 changing in file demo.prg line No. 108 from

Code: Select all

@ 250,  55 BUTTON Button_1 CAPTION "AddCol" ACTION Form_1.Grid_1.AddColumnEx (Nil, "Col"+alltrim(str(++n)), 100, NIL, {'TEXTBOX','NUMERIC','$ 999,999'})
to

Code: Select all

@ 250,  55 BUTTON Button_1 CAPTION "AddCol" ACTION Form_1.Grid_1.AddColumnEx (2, "Col"+alltrim(str(++n)), 100, NIL, {'TEXTBOX','NUMERIC','$ 999,999'})
Dragging GRID columns is possible only within currently visible columns and only from GRID, in which Items are.

In addition, the problem with ScrollBar in GRID was revealed. By moving the mouse pointer to ScrollBar the handle does not change, and the program "Sees" as if it was still on GRID, moving the slider horizontally may result in a drag effect.

I'm really sorry for the imperfections of my DragAndDrop.

Certainly better results could be obtained using the C language, but this is beyond my reach.

edk, fantastic work congratulations
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: Drag grid item to another grid

Post by jairpinho »

hello, I need to use drag grid in the same grade could help someone
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
Post Reply