Solved

How to tell if Items in listbox exist

Posted on 2004-03-28
2
258 Views
Last Modified: 2010-04-05
Hey,

How can I tell if there are items in a listbox. So when I click on a button it will say "items exist" if there are items in the listbox and if there are no items in the listbox it will say "no items in the listbox".

Cheers,

Computer Programer
0
Comment
Question by:computerprogramer
2 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 10697740
let's say you typed the string to search for in an edit box called Edit1

to test it, just say:

if ListBox1.Items.IndexOf(Edit1.Text) <> -1 then
  ShowMessage('Item Exists!')
else ShowMessage('No such item in the listbox!');
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 25 total points
ID: 10698424
You can test the Items count property to see if it is zero or not (zero being empty)

if ListBox1.Items.Count > 0 then
 ShowMessage('Items = ' + IntToStr(ListBox1.Items.Count)) //not empty
else
 ShowMessage('Items = 0'); //empty

Shane
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

829 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