Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Basic functions of the listbox explained Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
16-Jun-03
Category
VCL-General
Language
Delphi 2.x
Views
78
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Martin Ellis

I'm a beginner, how do i use the listbox??

Answer:

Ok heres some basic info on the listbox.
Their are many different functions to do with the listbox and it is not possible to 
display them all. So i am going to try and explain as many as possible. 

Number 1, Lets start from the beginning. 

OK so once you have placed the listbox you can add items at design time but to add 
them at runtime is a little more trick 

make a form with one listbox, 1 button and 1 edit box 

then add the following 

in the button1 onclick method plave 
1   
2   listbox1.items.add(edit1.text);


this then adds the current text in the edit box onto the bottom of the list you can 
add as many items as you like until you exit the program. 

Number 2, Taking it one step further. 

Ok so you have a listbox now with a few items in it, but what if you want to add 
one of the items in at say line 3 instead of the bottom line. This can easily be 
achieved by amending the above code, by changing the 'add' to 'insert' and then 
adding an index refrence you can place it in at the desired line. 

for example 
3   
4   listbox1.items.insert(3, edit1.text);


this will always then add the text from the edit box to the third line 

Number 3, The rest. 

Ok now you can get the total amount of items currently in a listbox by inserting 
the count procedure 

showmessage('Current Number of lines := ' + inttostr(listbox1.items.count));

this will then display the message 'Current Number of Lines := ??' where ?? is a 
number. 

Finally to get the currently selected item in the listbox you can add the following 
to the onclick method of your listbox 
5   
6   edit1.text := listbox1.items[listbox1.itemindex];


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC