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

How To know if The List Box Order Has Changed

Status
Not open for further replies.

bebbo

Programmer
Dec 5, 2000
621
GB
I have a list box which I ad to by using the addlistitem method. Basically I add each record of a small file. No problem.

The users are able to alter the order of the names on the list box. Should they do that I want to alter the order in the file. Therefore the next time the list box is filled it appears in the order the user has chosen. I know I can track this in the interactive change procedure. However this procedure is called each time the box is clicked.

As the box is clicked very frequently I only want to alter the file order should the order of the listbox change. How would I do that???

Thanks
 
I know I can track this in the interactive change procedure. However this procedure is called each time the box is clicked

I'm not really sure what do you want to achieve. But have you try to do it in VALID event ?

-- AirCon --
 
Basically my file has not index set. Lets say it is in this order

REcord1
Record2
Record3

These records show on my list box in this order. The operator can change this order say to record2, 3, and 1. This is no problem and this works.

However I want my file to know the order has changed. Otherwise the next time the list box is re-created the order will be back to 1,2,3.

Thanks

 
Hi

I've actually achieved this in the ProgrammaticChange procedure. Code as below:

SELECT STAFF
GO TOP
FOR ncnt = 1 To This.Listcount
REPLACE STAFF.SYSREF WITH INT(VAL(This.List(nCnt,1)))
REPLACE STAFF.TITLE WITH ALLTRIM(This.List(nCnt,2))
REPLACE STAFF.FIRSTNAME WITH ALLTRIM(This.List(nCnt,3))
REPLACE STAFF.SURNAME WITH ALLTRIM(This.List(nCnt,4))
IF !EOF()
SKIP 1
ENDIF
ENDFOR

Staff file should be the same size as the listcount. Just put the !EOF() incase it wasn't. Should never be called.

If anyone can see a problem with this please let me know.

Thanks, anyway
 
If you have a field for the order (e.g.: SeqNo and index by this field) it might be easier.

However, you can try this. I hope this is what you wanted. Modify it to suit your needs.


*----------------

DEFINE CLASS form1 AS form
Height = 173
Width = 204
DoCreate = .T.
AutoCenter = .T.
Caption = "Form1"
AlwaysOnTop = .T.
Name = "Form1"
Dimension arecord[1]

ADD OBJECT List1 AS listbox WITH ;
Height = 143, Left = 17, ;
Top = 15, Width = 170, ;
Name = "List1"


PROCEDURE addlistbox
Local lnX
With ThisForm.List1
If (.ListCount > 0)
For lnX = 1 to .ListCount
ThisForm.List1.RemoveItem(1)
Next
endif

Scan
.AddListItem(Test_Data.Test)
EndScan
EndWith
ENDPROC

PROCEDURE Load
Create cursor Test_Data (Test C(10))
Insert into Test_Data ( Test ) values ( 'Record 1' )
Insert into Test_Data ( Test ) values ( 'Record 2' )
Insert into Test_Data ( Test ) values ( 'Record 3' )
Insert into Test_Data ( Test ) values ( 'Record 4' )

Select * from Test_Data Into array ThisForm.aRecord
Go top
Browse nowait
ENDPROC


PROCEDURE Unload
Use in Test_Data
ENDPROC


PROCEDURE List1.Init
ThisForm.AddListbox()
ENDPROC

PROCEDURE List1.Click
Local lnX, lnIndex, lcValue

lnIndex = This.ListIndex
If (lnIndex > 1)
With ThisForm
lcValue = This.List(lnIndex)
For lnX = lnIndex to 2 step -1
.aRecord[lnX] = .aRecord[lnX-1]
Next
.aRecord[1] = lcValue

Set safety off
Zap
Set safety on
Append from array .aRecord
ThisForm.AddListbox()
Activate screen
Go top
Browse nowait
EndWith
endif
ENDPROC

ENDDEFINE

*----------------


-- AirCon --
 
Bebbo,

Almost at the same time :-D
Please try the code I posted, and tell me what I am missing

-- AirCon --
 
I've borrowed from my days in electronics to come up
with a solution to what I think you are attempting.

Correct me if I'm wrong.

In electronics, there is a circuit called a "Schmidt Trigger",
which has the ability to control and shape the profile of a signal.

Well, knowing that there are similar usages in
computer theory, and wanting to implement a structure
that would shave off many processor cycles from
list box processing, I came up with the following.

I'll leave it to you to implement the actual move
and state saving functionality.

This was fun!

Darrell

[tt]

Local o
o = CREATEOBJECT("listbox_schmidt_trigger")
o.SHOW()
Read EVENTS

**************************************************
*-- Class Library:
*-- ..\tektip answers\listbox_schmidt_trigger.vcx
**************************************************
*-- Author: Darrell C. Greenhouse
*-- 2004.02.06
*--
**************************************************
*-- Class: listbox_schmidt_trigger
*-- (..\tektip answers\listbox_schmidt_trigger.vcx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 02/06/04 05:27:11 PM
*-- A method to implement a self moving list box.
*
*

Define CLASS listbox_schmidt_trigger AS FORM
DoCreate = .T.
DataSession = 2
Height = 377
Width = 625
AutoCenter = .T.
BorderStyle = 2
Caption = ['A "ListBox" self-mover using a Quasi - Software Schmidt Trigger']
Name = "frmListBoxMoverExample"


Add OBJECT lstSelfMover AS LISTBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 12, ;
HEIGHT = 213, ;
LEFT = 25, ;
TOP = 24, ;
WIDTH = 576, ;
INTEGRALHEIGHT = .T., ;
NAME = "lstSelfMover"


Add OBJECT txtTriggerPosition AS TEXTBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
HEIGHT = 24, ;
LEFT = 110, ;
TOP = 259, ;
WIDTH = 72, ;
INTEGRALHEIGHT = .T., ;
NAME = "txtTriggerPosition"


Add OBJECT label1 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 14, ;
BACKSTYLE = 0, ;
CAPTION = "Ths List!", ;
HEIGHT = 24, ;
LEFT = 25, ;
TOP = 3, ;
WIDTH = 70, ;
NAME = "Label1"


Add OBJECT label2 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
BACKSTYLE = 0, ;
CAPTION = ".nStartValue", ;
HEIGHT = 18, ;
LEFT = 25, ;
TOP = 262, ;
WIDTH = 67, ;
NAME = "Label2"


Add OBJECT txtTriggerTrap AS TEXTBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
HEIGHT = 24, ;
LEFT = 110, ;
TOP = 286, ;
WIDTH = 72, ;
INTEGRALHEIGHT = .T., ;
NAME = "txtTriggerTrap"


Add OBJECT txtBeginPosition AS TEXTBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
HEIGHT = 24, ;
LEFT = 110, ;
TOP = 312, ;
WIDTH = 72, ;
INTEGRALHEIGHT = .T., ;
NAME = "txtBeginPosition"


Add OBJECT txtEndPosition AS TEXTBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
HEIGHT = 24, ;
LEFT = 110, ;
TOP = 338, ;
WIDTH = 72, ;
INTEGRALHEIGHT = .T., ;
NAME = "txtEndPosition"


Add OBJECT label3 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
BACKSTYLE = 0, ;
CAPTION = ".nTriggerValue", ;
HEIGHT = 18, ;
LEFT = 25, ;
TOP = 289, ;
WIDTH = 81, ;
NAME = "Label3"


Add OBJECT label4 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
BACKSTYLE = 0, ;
CAPTION = ".nStartPosition", ;
HEIGHT = 18, ;
LEFT = 25, ;
TOP = 315, ;
WIDTH = 81, ;
NAME = "Label4"


Add OBJECT label5 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
BACKSTYLE = 0, ;
CAPTION = ".nEndPosition", ;
HEIGHT = 18, ;
LEFT = 25, ;
TOP = 341, ;
WIDTH = 77, ;
NAME = "Label5"


Add OBJECT edtOpInfo AS EDITBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 16, ;
HEIGHT = 104, ;
LEFT = 204, ;
TOP = 259, ;
WIDTH = 396, ;
INTEGRALHEIGHT = .T., ;
NAME = "edtOpInfo"


Add OBJECT label6 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 12, ;
BACKSTYLE = 0, ;
CAPTION = "ListBox internal properties", ;
HEIGHT = 22, ;
LEFT = 25, ;
TOP = 235, ;
WIDTH = 161, ;
NAME = "Label6"

Add OBJECT label7 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 12, ;
BACKSTYLE = 0, ;
CAPTION = "Operational information", ;
HEIGHT = 22, ;
LEFT = 204, ;
TOP = 235, ;
WIDTH = 144, ;
NAME = "Label7"


** THIS Method **
** should be implemented by the listbox itself
** Did it here for expediency

Procedure processmove
Lparam oListBox
This.edtOpInfo.VALUE = ;
"List box item at row " + TRANSFORM(oListBox.nBeginPosition) + ;
" moved to row " + TRANSFORM(oListBox.nEndPosition)
Endproc


Procedure INIT
Select * ;
FROM (_samples+"\data\customer.dbf") ;
ORDER BY TITLE ;
INTO CURSOR tmpcust

With THIS
Scan
.lstSelfMover.ADDITEM(company)
Endscan

.txtTriggerPosition.CONTROLSOURCE = "thisform.lstSelfMover.nTriggerPosition"
.txtTriggerTrap.CONTROLSOURCE = "thisform.lstSelfMover.nTriggerTrap"
.txtBeginPosition.CONTROLSOURCE = "thisform.lstSelfMover.nBeginPosition"
.txtEndPosition.CONTROLSOURCE = "thisform.lstSelfMover.nEndPosition"

Endwith
Endproc

Procedure DESTROY
This.SaveState()
Clear EVENTS
Endproc

Procedure SaveState()
* Implement the order of the
* list box. Once again, the listbox
* should probably implement it.
*...
*...
*...
Endproc

Procedure lstSelfMover.MOUSEUP
Lparameters nButton, nShift, nXCoord, nYCoord

With THIS
.nBeginPosition = .nTriggerPosition
.nEndPosition = .LISTINDEX

.PARENT.REFRESH() && Demo

Thisform.ProcessMove(THIS)

.nTriggerTrap = 1
.nTriggerPosition = 0

.bNewTrap = .T. && For demostration only

.PARENT.REFRESH() && Demo
Endwith
Endproc


Procedure lstSelfMover.INIT
With THIS
.ADDPROPERTY("nTriggerPosition",0) && Initially selected row
.ADDPROPERTY("nTriggerTrap",1) && Traps the row
.ADDPROPERTY("nBeginPosition",0) && Beginning position for move
.ADDPROPERTY("nEndPosition",0) && Ending position for move

* This property is only for demontration
* purposes. It facilitates screen refreshing
* of the internal properties
.ADDPROPERTY("bNewTrap",.T.)
Endwith
Endproc


Procedure lstSelfMover.PROGRAMMATICCHANGE
With THIS
* Catch the trailing edge...
.nTriggerPosition = ;
IIF(.nTriggerTrap == 1, .LISTINDEX, .nTriggerPosition)

* And lock it!
.nTriggerTrap = BITRSHIFT(.nTriggerTrap ,1)

If .nTriggerTrap==0 .AND. .bNewTrap
.bNewTrap = .F.
Thisform.REFRESH()
Endif
Endwith
Endproc


Enddefine
*
*-- EndDefine: listbox_schmidt_trigger
**************************************************
[/tt]
 
Bug fix, cosmetic changes, and typo corrections

Darrell

[tt]
Local o
o = CREATEOBJECT("listbox_schmidt_trigger")
o.SHOW()
Read EVENTS


**************************************************
*-- Class Library:
*-- ..\tektip answers\listbox_schmidt_trigger.vcx
**************************************************
*-- Author: Darrell C. Greenhouse
*-- 2004.02.06
*--
**************************************************
*-- Class: listbox_schmidt_trigger
*-- (..\tektip answers\listbox_schmidt_trigger.vcx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 02/06/04 05:27:11 PM
*-- A method to implement a self moving list box.
*
*

Define CLASS listbox_schmidt_trigger AS FORM
DoCreate = .T.
DataSession = 2
Height = 377
Width = 625
AutoCenter = .T.
BorderStyle = 2
Caption = ['A "ListBox" self-mover using a Quasi - Software Schmidt Trigger']
Name = "frmListBoxMoverExample"


Add OBJECT lstSelfMover AS LISTBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 12, ;
HEIGHT = 213, ;
LEFT = 25, ;
TOP = 24, ;
WIDTH = 576, ;
INTEGRALHEIGHT = .T., ;
NAME = "lstSelfMover"


Add OBJECT txtTriggerPosition AS TEXTBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
HEIGHT = 24, ;
LEFT = 128, ;
TOP = 259, ;
WIDTH = 55, ;
INTEGRALHEIGHT = .T., ;
NAME = "txtTriggerPosition"


Add OBJECT label1 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 14, ;
BACKSTYLE = 0, ;
CAPTION = "Ths List!", ;
HEIGHT = 24, ;
LEFT = 25, ;
TOP = 3, ;
WIDTH = 70, ;
NAME = "Label1"


Add OBJECT label2 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
BACKSTYLE = 0, ;
CAPTION = ".nTriggerPosition", ;
HEIGHT = 18, ;
LEFT = 25, ;
TOP = 262, ;
WIDTH = 67, ;
NAME = "Label2"


Add OBJECT txtTriggerTrap AS TEXTBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
HEIGHT = 24, ;
LEFT = 128, ;
TOP = 286, ;
WIDTH = 55, ;
INTEGRALHEIGHT = .T., ;
NAME = "txtTriggerTrap"


Add OBJECT txtBeginPosition AS TEXTBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
HEIGHT = 24, ;
LEFT = 128, ;
TOP = 312, ;
WIDTH = 55, ;
INTEGRALHEIGHT = .T., ;
NAME = "txtBeginPosition"


Add OBJECT txtEndPosition AS TEXTBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
HEIGHT = 24, ;
LEFT = 128, ;
TOP = 338, ;
WIDTH = 55, ;
INTEGRALHEIGHT = .T., ;
NAME = "txtEndPosition"


Add OBJECT label3 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
BACKSTYLE = 0, ;
CAPTION = ".nTriggerTrap", ;
HEIGHT = 18, ;
LEFT = 25, ;
TOP = 289, ;
WIDTH = 81, ;
NAME = "Label3"


Add OBJECT label4 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
BACKSTYLE = 0, ;
CAPTION = ".nBeginPosition", ;
HEIGHT = 18, ;
LEFT = 25, ;
TOP = 315, ;
WIDTH = 81, ;
NAME = "Label4"


Add OBJECT label5 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 10, ;
BACKSTYLE = 0, ;
CAPTION = ".nEndPosition", ;
HEIGHT = 18, ;
LEFT = 25, ;
TOP = 341, ;
WIDTH = 77, ;
NAME = "Label5"


Add OBJECT edtOpInfo AS EDITBOX WITH ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 16, ;
HEIGHT = 104, ;
LEFT = 204, ;
TOP = 259, ;
WIDTH = 396, ;
INTEGRALHEIGHT = .T., ;
NAME = "edtOpInfo"


Add OBJECT label6 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 12, ;
BACKSTYLE = 0, ;
CAPTION = "ListBox internal properties", ;
HEIGHT = 22, ;
LEFT = 25, ;
TOP = 235, ;
WIDTH = 161, ;
NAME = "Label6"

Add OBJECT label7 AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Times New Roman", ;
FONTSIZE = 12, ;
BACKSTYLE = 0, ;
CAPTION = "Operational information", ;
HEIGHT = 22, ;
LEFT = 204, ;
TOP = 235, ;
WIDTH = 144, ;
NAME = "Label7"


** THIS Method **
** should be implemented by the listbox itself
** Did it here for expediency

Procedure processmove
Lparam oListBox
This.edtOpInfo.VALUE = ;
"List box item at row " + TRANSFORM(oListBox.nBeginPosition) + ;
" moved to row " + TRANSFORM(oListBox.nEndPosition)
Endproc


Procedure INIT
Select * ;
FROM (_samples+"\data\customer.dbf") ;
ORDER BY TITLE ;
INTO CURSOR tmpcust

With THIS
Scan
.lstSelfMover.ADDITEM(company)
Endscan

.txtTriggerPosition.CONTROLSOURCE = "thisform.lstSelfMover.nTriggerPosition"
.txtTriggerTrap.CONTROLSOURCE = "thisform.lstSelfMover.nTriggerTrap"
.txtBeginPosition.CONTROLSOURCE = "thisform.lstSelfMover.nBeginPosition"
.txtEndPosition.CONTROLSOURCE = "thisform.lstSelfMover.nEndPosition"

Endwith
Endproc

Procedure DESTROY
This.SaveState()
Clear EVENTS
Endproc

Procedure SaveState()
* Implement the order of the
* list box. Once again, the listbox
* should probably implement it.
*...
*...
*...
Endproc

Procedure lstSelfMover.MOUSEUP
Lparameters nButton, nShift, nXCoord, nYCoord

With THIS
If .nTriggerPosition <> 0 .and. ;
.nTriggerPosition <> .LISTINDEX && Fixes bug

.nBeginPosition = .nTriggerPosition
.nEndPosition = .LISTINDEX

.PARENT.REFRESH() && Demo

Thisform.ProcessMove(THIS)
Endif

.nTriggerTrap = 1
.nTriggerPosition = 0

.bNewTrap = .T. && For demostration only

If .nTriggerPosition == 0
.PARENT.REFRESH() && Demo
Endif
Endwith
Endproc


Procedure lstSelfMover.INIT
With THIS
.ADDPROPERTY(&quot;nTriggerPosition&quot;,0) && Initially selected row
.ADDPROPERTY(&quot;nTriggerTrap&quot;,1) && Traps the row
.ADDPROPERTY(&quot;nBeginPosition&quot;,0) && Beginning position for move
.ADDPROPERTY(&quot;nEndPosition&quot;,0) && Ending position for move

* This property is only for demontration
* purposes. It facilitates screen refreshing
* of the internal properties
.ADDPROPERTY(&quot;bNewTrap&quot;,.T.)
Endwith
Endproc


Procedure lstSelfMover.PROGRAMMATICCHANGE
With THIS
* Catch the trailing edge...
.nTriggerPosition = ;
IIF(.nTriggerTrap == 1, .LISTINDEX, .nTriggerPosition)

* And lock it!
.nTriggerTrap = BITRSHIFT(.nTriggerTrap ,1)

If .nTriggerTrap==0 .AND. .bNewTrap
.bNewTrap = .F.
Thisform.REFRESH()
Endif
Endwith
Endproc


Enddefine
*
*-- EndDefine: listbox_schmidt_trigger
**************************************************
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top