Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drag and drop row in a grid

Status
Not open for further replies.

serpico84

Programmer
May 18, 2011
13
IT
Hello everyone,
I tried to do research on this subject but honestly I did not find much about it, maybe I did not look good.
Give me advice, suggestions, code snippets, information on how to drag and drog of rows in a grid?

Thank you.
 
There are two fundamental problems here:

1) Grids are inextricably linked to an underlying cursor which doesn't natively support drag/drop of its rows

2) There is no row object. Grids are made up of columns

There are probably ways to kludge this together. (In my mind I'm seeing something that involves INSERT BLANK BEFORE, a command I've used once in 20 years.) But it's never going to be exactly what you want.
 
You can't drag a row as such. A row doesn't exist as an independent object.

The best you can do is to simulate the dragging of a row, either by dragging the entire grid or by dragging the textbox in one column of the row. Either way, it's up to you to interpret the drop action as applying to the row.

You first need to set to 1 the oleDragMode property of the grid, or of the textbox within the cell, as appropriate.

Next, in the same object's oleStartDrag, you store the data that you want to drag in the oDataObject object, which the method receives as a parameter. In this case, you would store the contents of the row being dragged.

You then write code in the oleDragDrop of the receiving object. The method receives the same oDataObject as above - the one containing the data from the row. The code must can access that data, and do anything you like with it. For example, if you are dropping the row on another grid, the code could insert a row in the cursor that populates the grid and fill it with the relevant data.

The above is a very quick overview. You really need to read up on the subject in more detail in the Help file. I suggest you give it a try, and come back if you have any detailed questions.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I have not personally done this and I don't dismiss the excellent and accurate advice given above, but if you do a Google search for:
vfp "drag and drop" grid
you might find some suggestions on how to address your issue.

Good Luck,
JRB-Bldr
 
Thank you all for the answers.
I read something about that also featured in vfp.
My goal is to create a grid with lines below the categories (rows purely descriptive) and to enable users to drag / move the content in these lines under other categories.

I understand that:
OleDragMode OleDropMode and must be set to 1
OLEStartDrag is the method that takes care of copying and OLEDragDrop is the method that "paste".

I made ??many tests but failed in the result.
I see to be able to find and study more, or take another route for my procedure.

Thanks,
F.
 
OLEStartDrag is the method that takes care of copying and OLEDragDrop is the method that "paste".

I think what you're missing is that, in OLEStartDrag you set up the Data object with the data that is to be dragged (the Data object is the object that the method receives as a parameter). In OleDragDrop, that data is available for you to do whatever you want with (again, the method receives the Data object as a parameter).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Could you give me an example using code?
I re-tried and tried but I can not move my line of data from one row to another.
I thought it was easier ...

Thanks,
F.
 
Serpico,

I really would stop forcing it, as initially said there are no row objects, so all you could drag&drop are single values anyway. I would consider using some third party grid, dbi or exontrol has some activex controls documented well for use with vfp. These offer row item objects and drag&drop of these.

Learning how drag & drop both via ole drag & drop and vfp drag & drop works is shown in the vfp samples in the solution.pjx, you could look into that, but it won't get you to your final goal anyway.

Bye, Olaf.
 
Serpikco,

I tend to agree with Olaf about using a third-party grid. However, since you asked for some example code ......

Let's suppose you want to drag the contents of the Address column in the selected row in the grid. In the grid's oleStartDrag:

Code:
LPARAMETERS oDataObject, nEffect

oDataObject.SetText(ALLTRIM(MyTable.Address))

And let's suppose you want to drop it in a textbox. In the oleDragDrop of the textbox:

Code:
LPARAMETERS oDataObject, nEffect, nButton, ;
  nShift, nXCoord, nYCoord

THIS.Value = oDataObject.GetData(1)

In both cases, the LPARAMETERS statement is built into the method. You don't have to add it yourself.

This is a highly simplified example. If you want to drag the entire row, you will need to concatenate all the values into a single string; do that in oleStartDrag; then, in the oleDragDrop, unpack the string into the separate values.

Also, I have not shown you how to change the mouse pointer to indicate where the user can and cannot do the drop. If necessary, you can come back to that later.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
move my line of data from one row to another.

Understand that the U/I will let you drag controls around but moving "data from one row to another" is entirely up to you to code. It is not a picnic with any of the U/I controls that are data-bound (grid, some lists).

The Listbox control does allow moving rows around (see the MoverBars property) but even that won't work if the underlying data source is a fixed source (table or array).

This just isn't something VFP natively supports. You will always be swimming upstream.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top