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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping record pointer on same record

Status
Not open for further replies.

AlastairOz

Technical User
Jul 27, 2010
81
AU
I have a list box which I am setting up a couple of
"up" and "Down" buttons so the user can reorder the items
to their choosing.
I got my code to work (Not sure if its the best way to do it,
but it works anyhow), but what I need to do is keep the
record in the list highlighted as it moves up or down, so I can keep moving it to the desired position.

Code:

LOCAL lnOld,lnNew
SELECT cSites
STORE RECNO() TO lnOld

SKIP -1

STORE RECNO() TO lnNew

replace testorder WITH lnold
SKIP 1
replace testorder WITH lnNew

=TABLEUPDATE(.t.,.t., "cSites")
thisform.pageframe1.page1.txtsiteList.Requery()
thisform.Refresh()


Any help would be much appreciated

Regards

Alastair
 
Listbox.Moverbars = .t., there you go.

You best use a recordsource of array then and afterwards can convert to a cursor/table again by Append From Array.

Bye, Olaf.
 
Hi,
So I looked at move bars property, and the row source type
needs to be 0 or 1.
I have my select into array for the data source.
I created a method "getData" and put this in the load event.
This contains the select into array statement.
How do I get this into the list box.
 
Alastair,

Unfortunately, you can't use MoverBars if you populate your listbox from an array. MoverBars are available if the RowSourceType is 0 or 1. For arrays, the RowSourceType is 5.

I suggest you set the RowSourceType to 0, and loop through the cursor, calling AddItem to add each record tothe listbox in turn.

Then, if you need to have the cursor reflect the order in which the user arranges the listbox, loop through the List property, copying each value back to the cursor, overwriting the previous values. You can do that in the OnMoveItem event, or when you are ready to save the form.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I appreciate all the help.
Just spent hours trying to recode this form with the above
suggestions, and just dug a deeper hole for myself.
So, returning to my origional code, which works exactly the way I need:
except I need to keep the same item selected in the list as
it moves up or down, until the user selects a different row/item.


This will then make the list box work exactly the way I planned.
 
Sorry I forgot it does indeed not work with Arrays, but the Items array of the listbox rather also is an array.

It's not that hard and the moverbars capbility of the listbox is rather comfortable.

Code:
Create Cursor curTestdata (cText C(20))
Insert into curTestdata values ("one")
Insert into curTestdata values ("two")
Insert into curTestdata values ("three")
Insert into curTestdata values ("four")

o = CreateObject("myForm")
o.Show(1)

Select curTestData
Browse

Define Class myForm as Form
   Datasession = 1
   Add Object Listbox1 as myListbox   
   Add Object CmdButton1 As CommandButton With;
     top = 200
     
   Procedure CmdButton1.Click()
      Thisform.Listbox1.Readout()
   EndProc 
EndDefine 

Define Class MyListbox as Listbox
   Moverbars = .t.
   
   Procedure Init()
      This.AddProperty("MyArray[1]",.f.)
      Select * From curTestdata Into Array This.myArray
      
      This.Rowsourcetype = 0
      For Each lcText In This.myArray
         This.Additem(lcText)
      EndFor 
   EndProc
   
   Procedure Readout()
      For lnCount = 1 To This.ListCount 
         This.myArray(lnCount)=This.List(lnCount)
      Endfor
      Zap In curTestdata
      Select curTestdata
      Append From Array This.myArray
   EndProc 
EndDefine

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top