473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Double-clicking to move an item between list boxes

patjones
931 Recognized Expert Contributor
Sometimes you might have two list boxes side by side, and want to double-click on an item in one box to move it to the other.

For instance, maybe the first list box contains a list of customers, and you want to perform some function (say, email them) that pertains to only a few of those customers. By double-clicking on the customer names you want, you get the desired list in the right hand box.

First, make a generic sub that takes two listbox arguments:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub MoveListItem(lstFrom As ListBox, lstTo As ListBox)
  3.      lstTo.AddItem (lstFrom.Value)
  4.      lstFrom.RemoveItem (lstFrom.Value)
  5. End Sub
  6.  
Then call this sub in the double-click events for the respective list boxes:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub lstA_DblClick(Cancel As Integer)
  3.     MoveListItem Me.lstA, Me.lstB
  4. End Sub 
  5.  
  6. Private Sub lstB_DblClick(Cancel As Integer)
  7.     MoveListItem Me.lstB, Me.lstA
  8. End Sub 
  9.  
Here you'll replace "lstA" and "lstB" with whatever the names of your list boxes are. You could modify this slightly by having a button situated between the boxes, and move the item from one to the other when the button is clicked.

It's a simple task but can come in handy!

Pat
May 1 '08 #1
6 9569
MMcCarthy
14,534 Recognized Expert Moderator MVP
Pat

Does this belong in VB. I don't think you can use .AddItem and .RemoveItem in VBA without at least adding a library.

If it needs to be moved just post a comment here and I'll take care of it.

Mary
May 28 '08 #2
patjones
931 Recognized Expert Contributor
Pat

Does this belong in VB. I don't think you can use .AddItem and .RemoveItem in VBA without at least adding a library.

If it needs to be moved just post a comment here and I'll take care of it.

Mary
I didn't have any reference issues when using this code in VB 6 (Access). Do you want me to post which references I have enabled just to be sure?

Thanks!

Pat
Jun 10 '08 #3
JustJim
407 Recognized Expert Contributor
@zepphead80
Hi Pat,

This is simple and elegant but, sadly errors out for me. Perhaps a library problem as Mary thought. I tried it at home using Access '03/VBA Retail 6.4.8869 with the following references included:

Visual Basic for Applications
Microsoft Access 11.0
Microsoft DAO 3.6
Microsoft ActiveX Data Objects 2.1
OLE Automation

Anything else you have loaded that might be relevant?

The error is 94: Invalid use of Null, and is on .AddItem line of the MoveListItem sub. A little hovering tells me that ListFrom.Value is null as is Me.lstA and Me.lstB from the calling subs.

Also, the helpfile for .AddItem and .RemoveItem states that the list box RowSourceType must be "Value List", which means you would have to build the contents of the first listbox by code or hard key it when you design the form. A pain, but a mild one.

Jim
Apr 15 '09 #4
JustJim
407 Recognized Expert Contributor
Sorry, ignore almost all of the above - I had one of the list boxes set to Extended Selection and that messed it up for some reason.

It now works fine with the basic libraries above, thank you.

The comment about the RowSourceType should be noted by others though.

(Blushing)Jim
Apr 15 '09 #5
patjones
931 Recognized Expert Contributor
Glad that my post was of assistance to you! No need to blush - show me someone who doesn't make these kinds of mistakes when programming in Access!

Pat
Apr 15 '09 #6
MMcCarthy
14,534 Recognized Expert Moderator MVP
Hi Pat

Haven't seen this thread in a while. My misinformation on .AddItem is probably a holdover from some of those earlier versions of Access libraries. I haven't tried to use it in years. I'll have to start experimenting again.

Thanks for the information. I always learn something new from the bytes experts no matter how much I think I know. It's why I love information sharing sites like this. Stops me from getting stuck in old patterns.

Mary
Apr 16 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Sydex | last post by:
When I compile code I get error C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(double)' in this part : double Integration::quad2d(double...
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
10
by: Robert Palma | last post by:
I'm having trouble figuring out how to pass a pointer to a double array (1 dimensional) to a C function. Declaring array as: double xx; Declaring func. int process( double *input ) Calling...
10
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
3
by: BlueTrin | last post by:
I am using a DLL written in C, it uses some pointers on functions, I have defined a wrapper around it in C# which uses some delegates: #region Delegates and Marshalling to call solvopt public...
67
by: lcw1964 | last post by:
This may be in the category of bush-league rudimentary, but I am quite perplexed on this and diligent Googling has not provided me with a clear straight answer--perhaps I don't know how to ask the...
1
by: JWest46088 | last post by:
I keep getting these error messages: area(double,double) in Rectangle cannot be applied to () return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter(); ...
2
by: dj10fld | last post by:
I am getting a (cannot convert double to double in assignment errors) here is a part of my code #include <iostream> #include <iomanip> #include <cmath> using namespace std; #define MaxSize...
2
by: Genro | last post by:
#include<stdio.h> #include<TX/graphics.h> #include<time.h> // I need help! struct Krug{ double _x; double _y; double _skox; double _skoy; double...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.