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: 4513
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 389 times
Been thanked: 111 times
Contact:

Re: Drag grid item to another grid

Post by esgici » Tue Jan 15, 2019 2:47 pm

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.JPG
like
Like.JPG (8.71 KiB) Viewed 276 times

Except leaderless status :(

We have a forum builder admin, it isn't :?
Viva INTERNATIONAL HMG :D

User avatar
mol
Posts: 3214
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 222 times
Been thanked: 123 times
Contact:

Post by mol » 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))


edk
Posts: 469
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 136 times
Been thanked: 381 times

Post by edk » Tue Jan 15, 2019 3:28 pm

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

Post Reply