Solved

2 List Boxes - Select item in one to then appear in listbox2

Posted on 2004-04-24
10
328 Views
Last Modified: 2010-05-18
I am trying to write the code to be able to select an item in one
listbox and then have that item appear in a second list box. I do
not want more than 20 items to be selected from first listbox.
0
Comment
Question by:James_Napier
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10908167
Hi
1. Do You want to select max 20 items at once or one at a time?
2. When do You want the selected item appear in the second listbox?
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10908184
for I:= 0 to ListBox1.Count - 1 do
  if ListBox1.Selected[I] then
    ListBox2.Items.Add(listBox1.Items[I]);


Shane
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 500 total points
ID: 10908220
procedure TForm1.Button1Click(Sender: TObject);
var
 I: Integer;
begin
 for I:= 0 to ListBox1.Count - 1 do
  if ListBox1.Selected[I] then
    ListBox2.Items.Add(listBox1.Items[I]);
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var
 I: Integer;
begin
 I:= listbox1.ItemIndex;
 if listbox1.SelCount > 20 then
  ListBox1.Selected[I]:= False;
end;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:James_Napier
ID: 10908558
Many thanks - would it make any difference if I
am using a DBListbox as listbox1?
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10908566
Nope, I dont believe so, it has the same properties..... Although, i didn't test it... im sure it wont matter

Shane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10908574
With DBListbox it absolutly don't work.
0
 

Author Comment

by:James_Napier
ID: 10908588
Agree - it doesn't seem to work. What would work in this case? I am transferring data
form a dbcontrolgrid into dblistbox1 and now need to allow users to select items in
dblistbox1(maximum total selection not greater than 20) and have then transfered to
a second listbox.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10908610
Sorry, hes right, there is no Multiselect ---- <SMILE>

Shane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10908665
Not quite.
Multiselect can be set at runtime.
What I mean was the trouble with unwanted change of data in database.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10908712
Right,  multiselect can be used at runtime, if you use the Selection array
however, you can't physically select from the OnClick event....and show the highlighted selections

designed for one selection .....


Shane
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question