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];