Are they editing the data? If not, you can use variable lookup list view based
on your temporary table. You can base the variable on the row id. That way when
they click on the move buttons it will stay highlighted.
Variable lookup list view is easier to refresh:
PROPERTY <componentid> refreshlist 'TRUE'
You can use the drag and drop within the variable lookup list view to move them
into a different position.
You will need to use the eep to reassign the row ids in your table “on drag
drop”. You can use properties to get the row it is is dropped on(itemindex).
You will also need to check the box in the properties of the variable list view
called “Drag List Items”
Hope this helps.
Dan Goldberg
From: dollar atabx
Sent: Wednesday, December 07, 2011 10:38 PM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Refresh DB Grid and, Use mouse to drag a row to a
different position
Hello,
My name is Pramote Padprom. I am now being trained at the Centre for Vocational
Building Technology, Thailand.
I was assigned to work with R:Base, and would like to ask the following:
Sortorder is a COLUMN in Components TABLE. It is used to sort the data for
a Report so it is easy to detect and easy to understand.
I created a form to allow users to change the order of rows using Sortorder.
The data type is Integer. I want it to sort the data in the form of "ORDER BY
Sortorder ASC" The Form contains a DB Grid with buttons: Button "move up" and
Button "move down," Button "Save" and Button "Close". When the user
selects a row that s/he wants in DB Grid and presses “Move up” the value of
Sortorder will reduce by 1 (the row will move up 1 row), but if you press the
button “Move down” the value of Sortorder increases by 1 (row will move down 1
row).
Values come from the Table Components. But to prevent errors, I created a
temporary table from the table Components designed to be used with the Form.
When you press the Save button it compares the Components and Temporary table.
Sortorder changes are then made to the Components table. I could use
advice on the following problems:
- Can not Refresh DB Grid (order by Sortorder ASC).
- Can not use the mouse to drag a row to a different position (different
sort order).
- I need a Function or EEP, so as not to have to repeatedly click select
rows on the DB Grid. I need the value for the current row without having to
click on it. Now (with Method 1 below), when the button “Move Up” is pressed,
SortOrder is reduced and the row moves up in DB Grid. When the button “Move
Up” is pressed a second time, SortOrder increases and the row moves back down
to it’s original position. I think I need a way (property) to get the value of
the “current” row without selecting it by clicking.
I've been searching for Rbase-L topics that relate to DB Grid Refresh and
RestoreOrder but I cannot find anything that helps yet.
Below is EEP code for 2 methods to do this. The first method works but it is
not elegant. The second method is elegant but does not work.
-- Create Temp table
-- start here: This is the EEP on Entry into Form (Form Start)
PROPERTY TABLE Test_Components CLOSE
SET ERROR MESSAGE 2038 OFF
DROP TABLE Test_Components
SET ERROR MESSAGE 2038 ON
Create Temp Table Test_components (Componentno Int,Engname Text 70,Thainame
Text 70, +
Descriptioneng Text 50,Descriptionthai Text 50,Comptypeno Numeric ,Uniteng Text
10,Unitqty Real, +
Comppurchaseuniten Text 25,Cost Real,Source Text 50,Density Real,Sortorder Int)
Insert Into Test_components Select
Componentno,Engname,Thainame,Descriptioneng,Descriptionthai, +
Comptypeno,Uniteng,Unitqty,Comppurchaseuniten,Cost,Source,Density,Sortorder +
>From Components +
Order By Sortorder
PROPERTY TABLE Test_Components OPEN
RETURN
--end here
Method: 1 Sorting of data succeeds..
--code on form of button 'Move up'
--start here
SET SORT ON
SET ERROR MESSAGE 2059 OFF
SET VAR vSortOr1 INTEGER = sortorder IN components WHERE
&RBTI_DBGRID_COLUMN=.RBTI_FORM_COLVALUE
SET VAR vSortOr2 INTEGER = (.vSortOr1 -1)
IF (vSortOr1 IS NULL OR vSortOr1=1) THEN
PAUSE 2 USING 'Select the row that sortorder > 1' CAPTION 'ERROR ' ICON
SERIOUS
GOTO Done
ELSE
UPDATE test_components SET sortorder = 0 WHERE sortorder =.vSortOr1
UPDATE test_components SET Sortorder = .Vsortor1 WHERE Sortorder = .vSortOr2
UPDATE test_components SET Sortorder =.vSortOr2 WHERE Sortorder = 0
PROJECT Ooh FROM test_components USING * ORDER BY sortorder ASC
PROPERTY table Ooh OPEN
PROPERTY TABLE test_components close
DROP TABLE test_components
PROJECT test_components FROM Ooh USING * ORDER BY sortorder ASC
PROPERTY table Ooh close
DROP TABLE Ooh
PROPERTY TABLE test_components OPEN
ENDIF
SET ERROR MESSAGE 2059 ON
SET VAR vSortxt =(CTXT(vSortOr2 -1))
SET VAR vValues = ('JUMP'&.vSortxt)
PROPERTY TABLE test_components .vValues
LABEL Done
CLEAR VAR vSortOr1,vSortOr2,vSortxt ,vValues
RETURN
--end here
Method 2 Fails.
--start here
SET SORT ON
SET ERROR MESSAGE 2059 OFF
SET VAR vSortOr1 INTEGER = sortorder IN components WHERE
&RBTI_DBGRID_COLUMN=.RBTI_FORM_COLVALUE
SET VAR vSortOr2 INTEGER = (.vSortOr1 -1)
IF (vSortOr1 IS NULL OR vSortOr1=1) THEN
PAUSE 2 USING 'Select the row that sortorder > 1' CAPTION 'ERROR ' ICON
SERIOUS
GOTO Done
ELSE
UPDATE test_components SET sortorder = 0 WHERE sortorder =.vSortOr1
UPDATE test_components SET Sortorder = .Vsortor1 WHERE Sortorder = .vSortOr2
UPDATE test_components SET Sortorder =.vSortOr2 WHERE Sortorder = 0
PROPERTY table test_components 'restoreorderby'
PROPERTY RBASE_FORM set_focus 'true'
PROPERTY RBASE_FORM refreshlist 'TRUE'
PROPERTY TABLE test_components 'DUPLICATE'
PROPERTY table test_components 'REFRESHLIST'
PROPERTY DBgrd_comp refreshlist 'TRUE'
ENDIF
RETURN
--end here
Do you have a suggestion for a way to do this is that is better and more
elegant?
Thank you for taking the time to provide guidance, and knowledge more ...
*I'm using R:Base 7.6 for windows
Thank you very much.
Pramote Padprom, Centre for Vocational Building Technology, Thailand