Welcome! Log In Create A New Profile

Advanced

[WD12] Move row up or down in a browsing table control

Posted by DarrenF 
Hi guys,

I'm looking for an easy way to move a row UP or DOWN in a browsing table control. Is there an easy way to to this with an exisitng command or am I missing something?

For example, if I have rows:

No Name       Amount   Date
1  aaaaaaaaaa  11.11  01/01/09
2  bbbbbbbbbb  22.22  02/02/09
3  cccccccccc  33.33  03/03/09
4  dddddddddd  44.44  04/04/09
If row 3 is currently selected and the 'Move Up' button is pressed, then rows 3 & 2 are effectively being transposed, so row 3 is placed into row 2 and row 2 is moved down to row 3 - is there a way of easily transposing these rows or do I need to defined individual variables (1 per column) to temporarily contain the data of the row I'm moving? ...or is there another (easier) way that you guys use that I can't see in the help files?

Cheers...

Jimbo
Re: [WD12] Move row up or down in a browsing table control
March 08, 2009 12:57AM

Hi,

the currently selected row is identified by TableSelect(Table), so, the command TableSelectPlus(TableSelect(Table)+1) will move one line down. However, you can't move down over the last row which ist identified by TableCount(Table) and you have to take care that any row of the Table is selected at all and - when going up - that you don't go below row#1

Button down:
IF TableSelect(Table) > 0 and TableSelect(Table) < TableCount(Table) THEN
TableSelectPlus(Table,TableSelect(Table)+1)
END

Button up:
IF TableSelect(Table) > 1 THEN
TableSelectPlus(Table,TableSelect(Table)-1)
END

Regards,
Guenter

Hi Guenter,

Yes I realise what you are saying - I've already implemented First/Last/Prev/Next (moving the highlight bar) - What I'm talking about is moving the actual row data contents UP and DOWN.

Any Ideas?

Cheers...
Hi Darren
Effectively all you are doing is swapping lines. We use a procedure which receives the table name and the direction (1 to demote line, -1 to promote).
PROCEDURE SwapLines_(_sTable,_iDirection = -1 )
li_currentrow is int = TableSelect({_sTable,indControl}) + _iDirection
ls_templine is string
IF li_currentrow > 1 THEN
	ls_templine = {_sTable,indControl}[{_sTable,indControl}]
	TableDelete({_sTable,indControl})
	TableInsert({_sTable,indControl},ls_templine,li_currentrow)
	TableSelectPlus({_sTable,indControl},li_currentrow)
END
HTH

David
Louis Verbraak
Re: [WD12] Move row up or down in a browsing table control
March 09, 2009 08:27AM
Hello Darren,

You can swap lines by using: Table1[1] <=> Table1[2]
After that you have to set the focus to the line you want: TableSelectPlus(Table1,2)

HTH.
marcel.berman@managingbusiness.be.pcs
Re: [WD12] Move row up or down in a browsing table control
March 09, 2009 09:04AM
Hi !

You should look for the <=> operator ...
It's really usefull in order to swap values ...
You can easlily swap the content of two lines of a memory table (or any
variable of a simple type) like this :
MyTable[LineX] <=> MyTable[LineY]
Hope this help !


--
Marcel Berman
Président de Be-Dev.be (www.be-dev.be) (Belgique)
Membre du CA de Wind'Asso (www.windasso.org) (France)
Be-Dev.be et Wind'Asso sont des associations d'utilisateurs des produits
PC-Soft
Message forwarded from pcsoft.us.windev
Hi guys,

Thanks for taking the time...

Yes I found the <=> operator after David's reply, but I think my main discovery was that a var can be defined as a string and then have a whole table row moved into it (each column separated by TAB - which was an addiitional discovery for mesmiling smiley ), and doesn't require a var for each element of a table row.

Thanks again...
Hi all,

Just a bit of feedback on how I decided to implement my row swapping. All of your feedback proved useful in one way or another, and who knows, this may prove useful to someone in the future winking smiley

Because of the way my maitenance windows work, I decided to use the sequence number I already have on each row of my table to keep the window/table row sequence and to use HModify on the row pairs as I go along instead of scanning thru the table at the end when the user presses the final OK button.

The "Move Up" code is as follows and the "Move Down" is just the opposite:

// Locate the currently selected row
glocaliRowSubscript1 is int = TableSelect(WTABLE_Spec_Sheet_Item)

// If we are at the top of the TABLE, then we can't MOVE UP any further
IF glocaliRowSubscript1 < 2 THEN
	RETURN
END

// Select the row above the one selected by the user ready for the swap
TableSelectPlus(WTABLE_Spec_Sheet_Item,glocaliRowSubscript1 - 1)

// Locate the other currently selected row
glocaliRowSubscript2 is int = TableSelect(WTABLE_Spec_Sheet_Item)

// Update - move row up
HReadSeek(Spec_Sheet_Item,ID,WTABLE_Spec_Sheet_Item.WTABLECOL_ID[glocaliRowSubscript1])
Spec_Sheet_Item.nSequence = WTABLE_Spec_Sheet_Item.WTABLECOL_NSeq[glocaliRowSubscript2]
HModify(Spec_Sheet_Item)

// Update - move row down
HReadSeek(Spec_Sheet_Item,ID,WTABLE_Spec_Sheet_Item.WTABLECOL_ID[glocaliRowSubscript2])
Spec_Sheet_Item.nSequence = WTABLE_Spec_Sheet_Item.WTABLECOL_NSeq[glocaliRowSubscript1]
HModify(Spec_Sheet_Item)

// Refresh the table
TableDisplay(WTABLE_Spec_Sheet_Item)

// Select/highlight the row that was moved up in the table
TableSelectPlus(WTABLE_Spec_Sheet_Item,glocaliRowSubscript2)
Stefan Bentvelsen
Re: [WD12] Move row up or down in a browsing table control
March 19, 2009 11:43AM
Hi Darren,

take care of the fact that a table column (string type) can contain TAB-characters itself. I'm afraid that if you put such a table line in a string variable and put it in another table line the result is not exact what you would expect.
Yes Stefan,

Thanks for that - I discovered that during my investigations - I now make sure that I refer to columns specifically by their column names...
Author:

Your Email:


Subject:


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.
Message: