473,785 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ 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 9600
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
9893
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 (*func)(double,double)) { nfunc = func ; return qgaus(f1,x1,x2);//error there
20
17835
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; std::vector<double>::size_type size = src.size(); dest.reserve(size); for (std::vector<int>::size_type i = 0;
31
6651
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 variable becomes 364 and the other one becomes 365. Does anyone have any insight to what the problem is? Thanks in advance. Bjørn
10
8662
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 func. as one of the following:
10
18774
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
2884
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 delegate double funCallback(double x); public delegate double funcCallback(double x); public delegate void gradCallback(double x, double v); public delegate void gradcCallback(double x, double v);
67
9927
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 quesion. I have begun to familiarize myself here with the gcc compiler in a win32 environment, in the form of MinGW using both Dev C++ and MSYS as interfaces. I have recompiled some old math code that uses long double types throughout and...
1
8228
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(); ^ perimeter(double,double) in Rectangle cannot be applied to () return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter(); ^ setSides(double,double) in Rectangle cannot be applied to (double)...
2
5597
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 1000 double loancalc (double *months, double *intrat, double *princ, double calcprnc, double calcpay, double calcbal, double calcnew, double calcInt); double display (double *months, double calcprnc, double calcpay, double calcbal, double...
2
5805
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 _granx1;
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9949
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6739
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
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 we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.