user list order form
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
user list order form

 
Post new topic   Reply to topic    CADForums.net Forum Index -> Cadence
Author Message
anandganesan@gmail.com
Guest





Posted: Fri Dec 17, 2004 3:06 pm    Post subject: user list order form Reply with quote

hi
i have a list and i want to display it on a form and let the user
rearrange it in his suitable manner. finally the form needs to be
closed with the reordered list. does anyone already have a code for
this or can you suggest the simplest way of doing this?

thanks.

anand.

Back to top
S. Badel
Guest





Posted: Fri Dec 17, 2004 7:37 pm    Post subject: Re: user list order form Reply with quote

here is a bit of code. it supposes your list is a list of integers. it's
important because it uses a report field. could however be tweaked
easily for other data type or even for list of lists.
usage: OLReorderList( mylist ) => reordered_list

OLListField = hiCreateReportField(
?name 'list
?title "List"
?titleAlignment 'left
?headers '( ("Item" 300 left int nil ) )
?choices nil
)

OLUpButton = hiCreateButton(
?name 'upBtn
?buttonText "Up"
?callback "OLUpCB(hiGetCurrentForm())"
)

OLDownButton = hiCreateButton(
?name 'downBtn
?buttonText "Down"
?callback "OLDownCB(hiGetCurrentForm())"
)

OLForm = hiCreateAppForm(
?name 'adeTxtOutSetupForm
?formTitle "Order List"
?buttonLayout '(OKCancel)
?buttonDisabled '( Help )
?dialogStyle 'modal
?fields list(
list( OLListField 10:10 400:200 100 )
list( OLUpButton 450:66 50:30 )
list( OLDownButton 450:122 50:30 )
)
?initialSize 520:250
?minSize 520:250
?maxSize 520:250
) ; hiCreateAppForm

; procedure to swap two adjacent items in a list
procedure( OLSwapItems(l a b)
let( ( (x min(a b)) (y max(a b)) )
if( x==1 then
cons( cadr(l) cons( car(l) cddr(l) ) )
else
cons( car(l) swapItems(cdr(l) x-1 y-1) )
) ; if
) ; let
) ; procedure

procedure( OLUpCB(form)
; process each item from the selection
let( (selection)
selection = form~>list~>value
foreach( item form~>list~>value
; exchange the item and it's predecessor
when( item
form~>list~>choices = OLSwapItems(form~>list~>choices item item+1)
)
) ; foreach
form~>list~>value=mapcar(lambda( (x) x=x-1 ) selection )
) ; let
) ; procedure

procedure( OLDownCB(form)
; process each item from the selection
let( (selection)
selection = form~>list~>value
foreach( item reverse(selection)
; exchange the item and it's predecessor
when( item+1!=length(form~>list~>choices)
form~>list~>choices = OLSwapItems(form~>list~>choices item+1 item+2)
)
) ; foreach
form~>list~>value=mapcar(lambda( (x) x=x+1 ) selection )
) ; let
) ; procedure

procedure( OLReorderList( l )
OLForm~>list~>choices = mapcar( 'list l )
if( hiDisplayForm(OLForm) mapcar( 'car OLForm~>list~>choices ) l )
) ; procedure



anandganesan@gmail.com wrote:
Quote:
hi
i have a list and i want to display it on a form and let the user
rearrange it in his suitable manner. finally the form needs to be
closed with the reordered list. does anyone already have a code for
this or can you suggest the simplest way of doing this?

thanks.

anand.
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> Cadence All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB