New to VB, looking for help

sewoo used Ask the Experts™
I'm trying to edit an existing program that has an inventory list and a shopping cart list.  The shopping cart list begins empty, and as you select items from the inventory list on the left, they are added to the shopping cart on the right.  The original program was designed to use with a mouse and double-click to add/delete method.  I'm just trying to edit the code so that there will be arrows to scroll up and down the lists, as well as left and right to go between the two lists, so the user has to use an add/delete button.  I think I've got the scroll up and down working, but I am stuck trying to figure out how to go back and forth between the two lists.

Any help would be appreciated
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dirk HaestProject manager

You'll have to use the tab or setfocus

Suppose you're in list1
After he reached the end, you want automatically to jump to list2
Just do list2.setfocus

use the keyup/keydown event of the two lists as the user presses this button (left/right) then the list focus should change but i recommend not to follow this practice provide the user with some combination like ctrl+right arror etc...


Option Explicit
' the below code is used to add the
'items from listbox1 to listbox2 and delete the item from listbox1
'Command Button >>

Private Sub Command1_Click()
List2.AddItem List1.List(List1.ListIndex)
List1.RemoveItem (List1.ListIndex)
End Sub
' to move the items from listbox2 to listbox 1 and delete the item from listbox2
Private Sub Command2_Click()
List1.AddItem List2.List(List2.ListIndex)
List2.RemoveItem (List2.ListIndex)
End Sub

Private Sub Form_Load()

' this is used as the default values in the listbox1
List1.AddItem "a"
List1.AddItem "b"
List1.AddItem "c"
List1.AddItem "d"
List1.AddItem "e"
End Sub

Hope this will be of some sort of help to you
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


One more question...  I have the two listboxes, inventory is static and the shopping cart can have items added or subtracted to it.

If I only have one button to add/delete, how can I check to see if the shopping cart list is selected so that I know when to delete?


I have a version of it that partially works, but the shopping cart list is on the right and when I move to that list and delete, it deletes the highlighted item, but does not highlight another item, unless I got back to the inventory list and back over to the shopping cart list to highlight a new item
Set the ListIndex to a valid index. Like

List1.ListIndex = 1

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial