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
Solved

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

Posted on 2004-04-24
10
327 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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