Welcome! Log In Create A New Profile


[WD23] DnD from Table to TreeViewTable

Posted by Ola 
[WD23] DnD from Table to TreeViewTable
August 27, 2020 12:03PM
Hi all,

I am trying to make a rather simple one-way DragAndDrop move operation work from a Table (called Table) to a TreeViewTable (called TVT). The Drag part goes as planned, but I have difficulties in trying to land the "droppings" on the correct line in the TVT. There happens to be a simple sample for just this scenario in the WD online help, but it's messed up; when landing the dropping it uses the TreeSelect command to get the target line, but this works only in a TreeView control, not in a TreeVievTable!

I have tried TVT.Select() and TVT.Select(-1), but they do not work; the result I always get is the line that was selected before the DnD operation was started.

I also tried the code of an older (WD15) DnD sample, where the target line was retrieved using the X and Y positions of the mouse cursor, but it also does not seem to work reliably, as it needs to know the exact height of the target table's header line, which in the sample is 24 pixels, but may vary in real life, and I haven't found a way to get this info reliably.

So how do I select the correct line in the target TreeViewTable's drop event?

Maybe I'm just missing something very simple, as usualeye popping smiley

Best regards
Re: [WD23] DnD from Table to TreeViewTable
August 27, 2020 09:59PM
tableinfoXY comes to mind
Re: [WD23] DnD from Table to TreeViewTable
August 28, 2020 01:12PM
Hi Argus,

Thank you for the suggestion.

I already tried that, and finally it was the only solution that I could use. But it is still problematic. The cursor position must be corrected with the height of the header line to get the correct landing row, and (somebody correct me if I am wrong) this info obviously can only be found by trial and error. So if the header height is ever touched, maybe just accidentally, then the code will not work any more. Here's my code (modified from a WD15 DnD sample):

//See also: TVT, TableDrag, TVTRollover()


sSourceLine is string //Contents of the row selected in the source table
nLandingRow is int //Landing/target row for the dropping
nPosXTVT is int
nPosYTVT is int
nCorrection is int
nCurPos is int //Cursor position

// Coordinates of the table
nPosXTVT = {_DND.TargetControl,indControl}..X
nPosYTVT = {_DND.TargetControl,indControl}..Y

// To find out the number of the landing row, 
// we need to know the position of the cursor:
nCurPos = CursorPos(cpClient)

IF nCurPos = -1 THEN ReturnToCapture() //Target was outside the limits

//Retrieve the source row that is being moved. 
//In the WD sample the first element corresponds to the number of the row to move.
//Here the 1st item of sSourceLine contains the email's Id (SPOSTI.SPID):
sSourceLine = DnDGetData(CF_TEXT)

//Find the landing row's number.
//The correction value (28 here, 24 in sample) was found by trial 
//and error; do not change it or the height of the TVT header row:
nCorrection = 28 //Adjustment for the height of the header row.
nLandingRow = TableInfoXY({_DND.TargetControl,indControl},... 

//Then do what you want with the data in the source and landing rows...

Best regards
Re: [WD23] DnD from Table to TreeViewTable
September 01, 2020 11:20PM
Your code seems overtly complicated. Maybe it's because it's coming from a very old example.

According to the help (and my experience), you should get your line number in ONE instruction

Re: [WD23] DnD from Table to TreeViewTable
September 02, 2020 12:33PM
Hi Argus,

Thank you again.

I re-read TFM, but still can't get it to work in a simpler code. I tried this:

//Alternative 2 (new) - No luck: first gives a random row 
//(= two rows below the previously selected, original row), 
//then the last selected row, but never the row over which the left mouse button was released:

nLandingRow = TableInfoXY({_DND.TargetControl,indControl},tiLineNumber,nPosX,nPosY)

//nLandingRow = TableInfoXY(TVT,tiLineNumber,nPosX,nPosY) //Also a direct reference doesn't work.

And I even tried de-selecting any previous selections in the TVT with the TVT.SelectMinus()-command prior to doing TableInfoXY()

Obviously WD has some problems getting the correct row?, as it advises:
"Using MouseXPos and MouseYPos
To use MouseXPos and MouseYPos in the X and Y parameters of the function, make sure that a single mouse click will trigger the execution of the code containing this function.
For example, the event "Selecting a row" of a Table control can be started by a simple click but also by a keyboard selection. Therefore, MouseXPos and MouseYPos should not be used in this event. Use an optional event instead. In this example, use the optional event "Left button down" on aTable control."

- so what does it mean? I'm doing a drag and drop operation, and their dnd-events have been specified in the windows's initialization code? Should I instead specify them in the control's initialization codes?

I would really like to see a simple example of a working dnd-operation, where the target is a TreeViewTable. The old version 15 sample works, but it has the potential stability/reliability-fault I've already described.

Best regards

Your Email:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.