Solved

How to tell if Items in listbox exist

Posted on 2004-03-28
2
259 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
[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
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 111
delphi parse string to params 3 158
Firemonkey android show image from resource ? 1 58
Delphi TListView and TEdit (Select item and input into TEdit) 10 51
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

730 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