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

mover form listboxes with 2 columns 1

Status
Not open for further replies.

dc509

IS-IT--Management
Feb 27, 2003
16
0
0
US
I'm trying to set up a mover form with 2 listboxes, each have 2 columns and an Add button.

Listbox1 has rowsourcetype of 6 and works like its supposed to.

When I run the form and click the Add button, I get an error:

'Function argument value, type, or count is invalid'

Here's the code in the click event of the add button:

THISFORM.List2.AddListItem(THISFORM.List1.Value)
THISFORM.List1.BoundColumn=2
THISFORM.List2.AddListItem(THISFORM.List1.value,Thisform.List2.ListIndex,2)
THISFORM.List1.RemoveItem(THISFORM.List1.ListIndex)

The first column moves, so I think the error is occurring when I try to move the second column.

If there is a better way to do this, please let me know.

Would using arrays as rowsourcetype be better?

Thanks
 
You may want to look at the Mover classes in the Component Gallery's Foundation Classes (look in the User Controls). There are help file entries and sample code for using these - why reinvent the wheel? Welcome to OOP!

Rick
 
Since List1's rowsource is fields from a cursor, you
have to delete the cursor rows.

Also, if list2's rowsourcetype is 0, just use the
additem() method to add the first column and then the
addlistitem() method to add the contents of the second column.

Here's an example that shows moving single and multiple
selected items:

You should have no problem figuring out how to move items
back to the source listbox.


oForm = CREATEOBJECT("MyForm")
oForm.SHOW()
READ EVENTS


DEFINE CLASS MyForm AS FORM

DATASESSION = 2
WIDTH = 430
AUTOCENTER = .T.
CAPTION = "Listbox mover example"

* The source listbox

ADD OBJECT lstSource AS LISTBOX WITH ;
LEFT = 5, ;
WIDTH = 200, ;
HEIGHT = 200, ;
ROWSOURCE = "test.ListItem1,ListItem2", ;
ROWSOURCETYPE = 6, ;
COLUMNCOUNT = 2, ;
MULTISELECT = .T., ;
INTEGRALHEIGHT = .T., ;
FONTNAME = "courier new"


* The target listbox

ADD OBJECT lstTarget AS LISTBOX WITH ;
LEFT = THIS.lstSource.LEFT + THIS.lstSource.WIDTH + 20, ;
WIDTH = 200, ;
HEIGHT = 200, ;
COLUMNCOUNT = 2, ;
INTEGRALHEIGHT = .T., ;
SORTED = .T., ;
FONTNAME = "courier new"

* Command button to move a single item from source to target

ADD OBJECT cmdSnglMover AS COMMANDBUTTON WITH ;
TOP = THIS.lstSource.TOP + THIS.lstSource.HEIGHT + 10, ;
HEIGHT = 24, ;
AUTOSIZE = .T., ;
CAPTION = "Move Single Selects"

* Command button to move multiple items from source to target

ADD OBJECT cmdMultiMover AS COMMANDBUTTON WITH ;
TOP = THIS.cmdSnglMover.TOP, ;
LEFT = 150, ;
HEIGHT = 24, ;
AUTOSIZE = .T., ;
CAPTION = "Move Multiple Selects"

* Command button to reset listboxes and data cursor

ADD OBJECT cmdReset AS COMMANDBUTTON WITH ;
TOP = THIS.cmdSnglMover.TOP, ;
LEFT = 300, ;
HEIGHT = 24, ;
AUTOSIZE = .T., ;
CAPTION = "Reset"


* Form and context settings

PROCEDURE LOAD
SET DELETED ON
SET SAFE OFF

CREATE CURSOR test (ListItem1 C(8), ListItem2 C(8))
INDEX ON ListItem1 TAG ListItem1
THIS.LoadData()
ENDPROC


* Load lstSource's data cursor

PROCEDURE LoadData
ZAP IN "test"
FOR i = 1 TO 100
INSERT INTO test (ListItem1,ListItem2) VALUES ("Col1 "+(STR(i,3)),"Col2 "+(STR(i,3)))
NEXT
ENDPROC


* Form is initing

PROCEDURE INIT
THIS.lstSource.REQUERY()
ENDPROC


* Form is dying

PROCEDURE DESTROY
CLEAR EVENTS
USE IN "test"
ENDPROC


* Move a single selected items

PROCEDURE cmdSnglMover.CLICK
WITH THISFORM
IF .lstSource.LISTINDEX <> 0

.lstTarget.ADDITEM(.lstSource.LISTITEM(.lstSource.LISTINDEX,1))

.lstTarget.ADDLISTITEM(.lstSource.LISTITEM(.lstSource.LISTINDEX,2),;
.lstTarget.LISTCOUNT,2)

DELETE NEXT 1 IN &quot;test&quot;
.lstSource.REQUERY()

ENDIF
ENDWITH
ENDPROC


* Move any multiple selected items

PROCEDURE cmdMultiMover.CLICK
LOCAL i, lbMoved, lnDeleteRecs
LOCAL ARRAY laDeleteRecs[1]

lnDeleteRecs = 0

WITH THISFORM
FOR i = 1 TO .lstSource.LISTCOUNT
IF .lstSource.SELECTED(i)

* Save the record # of each selected item
lnDeleteRecs = lnDeleteRecs + 1
DIME laDeleteRecs[lnDeleteRecs]

=SEEK(.lstSource.LISTITEM(i,1),&quot;test&quot;)
laDeleteRecs[lnDeleteRecs] = RECNO(&quot;test&quot;)

.lstTarget.ADDITEM(.lstSource.LISTITEM(i,1))

.lstTarget.ADDLISTITEM(.lstSource.LISTITEM(i,2), ;
.lstTarget.LISTCOUNT,2)

lbMoved = .T.
ENDIF
NEXT

IF lbMoved

FOR i = 1 TO lnDeleteRecs
DELETE RECORD (laDeleteRecs[ i ]) IN &quot;test&quot;
NEXT

.lstSource.REQUERY()

ENDIF

ENDWITH
ENDPROC


* Reset the listboxes and data cursor

PROCEDURE cmdReset.CLICK
WITH THISFORM
.LoadData()
.lstSource.CLEAR()
.lstTarget.CLEAR()
.lstSource.LISTINDEX = 0
.lstTarget.LISTINDEX = 0
.lstSource.REQUERY()

ENDWITH
ENDPROC

ENDDEFINE





'We all must do the hard bits so when we get bit we know where to bite' :)
 
darrellblackhawk

An excellent example. Worth a star.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top