Welcome! Log In Create A New Profile

Advanced

WM22 Android : Move item in table or looper

Posted by Peter Muckle 
WM22 Android : Move item in table or looper
October 15, 2018 02:01PM
Hi All,

I know I have seen several threads on this, but can't find them again...

I would like to move an item up/down a table or looper, by selecting the line and using up/down arrow buttons.

Could someone point me to a thread, or alternatively give some hints and or code. There is a numeric 'sort_order' field.

Thanks

Peter
Re: WM22 Android : Move item in table or looper
October 15, 2018 03:41PM
Hi Peter,

This should work in WM Android:

// UP Button
IF TableSelect(Table_temp) =-1 THEN RETURN
TableMoveLine(Table_temp,rowSelected,amPrevious,amSwap)

// DOWN Button
IF TableSelect(Table_temp) =-1 THEN RETURN
TableMoveLine(Table_temp,rowSelected,amNext,amSwap)

Regards
Steven Sitas
[www.alpha360.biz]



Edited 2 time(s). Last edit at 10/15/2018 03:45PM by StevenSitas.
Re: WM22 Android : Move item in table or looper
October 15, 2018 03:49PM
Hi

of course, it depends on the TYPE of table.. if linked to a file or query, you need a completely different code.

Best regards

Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Free Video Courses, free WXShowroom.com, open source WXReplication, open
source WXEDM.

More information on [www.fabriceharari.com]
Re: WM22 Android : Move item in table or looper
October 15, 2018 05:36PM
Thanks for the input Steven and Fabrice

I am working on a browsing Looper (I should have said)

This is the code I have cobbled together, which moves the selection to the left:

// looper based on a query sorted on 'sort-order' decimal field

// Locate the currently selected row
glocaliRowSubscript1 is int = LooperSelect(LOOP_QRY_species2)
// If it is the first row in looper nothing to do
IF glocaliRowSubscript1 < 2 THEN
	RETURN
END
// If it is the 2nd row we swap the sort_order decimal
IF glocaliRowSubscript1 = 2 THEN
	// copy GUID of selected row
	original_GUID is UNICODE string = LOOP_QRY_species2.ATT_settings_species_GUID
	original_sort is currency = LOOP_QRY_species2.ATT_sort_order
	// Select the row above
	LooperSelectPlus(LOOP_QRY_species2,1)
	sONE_ABOVE is UNICODE string = LOOP_QRY_species2.ATT_settings_species_GUID
	// locate original to update
	HReadSeek(settings_species,usGUIDsettings_species,sONE_ABOVE)
	swap_sort is currency = settings_species.sort_order
	settings_species.sort_order=original_sort
	HModify(settings_species)
	// swap to original
	HReadSeek(settings_species,usGUIDsettings_species,original_GUID)
	settings_species.sort_order=swap_sort
	HModify(settings_species)
ELSE
	// find sort_order of the two rows above, add values together and divide by 2 for new sort_order
	original_GUID is UNICODE string = LOOP_QRY_species2.ATT_settings_species_GUID
	// Select the row above
	LooperSelectPlus(LOOP_QRY_species2,glocaliRowSubscript1 - 1)
	glocaliRowSubscript2 is int = LooperSelect(LOOP_QRY_species2)
	sONE_ABOVE is UNICODE string = LOOP_QRY_species2.ATT_settings_species_GUID
	// Select the 2ND row above the one selected by the user ready for the swap
	LooperSelectPlus(LOOP_QRY_species2,glocaliRowSubscript2 - 1)
	sTWO_ABOVE is UNICODE string = LOOP_QRY_species2.ATT_settings_species_GUID
	// get the sort-order of one above
	HReadSeek(settings_species,usGUIDsettings_species,sONE_ABOVE)
	cyOne_above is currency = settings_species.sort_order
	// get the sort order of two above
	HReadSeek(settings_species,usGUIDsettings_species,sTWO_ABOVE)
	cyTwo_above is currency = settings_species.sort_order
	// add together
	cyNCombined is currency = cyOne_above+cyTwo_above
	cyNCombined=cyNCombined/2
	// update the selected record with the new sort_order
	HReadSeek(settings_species,usGUIDsettings_species,original_GUID)
	settings_species.sort_order=cyNCombined
	HModify(settings_species)
	
END

// refresh the looper
HExecuteQuery(QRY_species_by_preset,hQueryDefault,gsPreset)
LooperDisplay(LOOP_QRY_species2)
// Select/highlight the row that was moved up in the table
LooperSelectPlus(LOOP_QRY_species2,glocaliRowSubscript1-1)

This combines a method mentioned before by Fabrice with one shown by Darren F.

If anyone knows of a simpler method...

Cheers

Peter
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: