Solved

Delphi combobox list items refresh/delete/match index

Posted on 2011-03-04
4
1,935 Views
Last Modified: 2012-05-11
with calc do
  begin
  if portLen > 1 then
    Items.add('text1');
  if portLen > 2 then
    Items.add('text2');
  end;
end;

Open in new window


Problem is that the code in this procedure may be referenced multiple times and every time it is referenced it adds more items to the bottom of the combobox list. What I need to do is either delete the list and start over, or match the text to an index so I can populate the combobox if certain conditions are true, or something of that sort.

Or maybe being able to hide the items in the drop down based on certain conditions? This may be the most elegant solution, but I cannot figure out how to do it.

Any help would be appreciated. Thank you!
0
Comment
Question by:keats88
[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
  • 3
4 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 125 total points
ID: 35040349
call procedure clear


with calc do
begin
  Clear;
  if portLen > 1 then
    Items.add('text1');
  if portLen > 2 then
    Items.add('text2');
  end;
end;

Open in new window

0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35040355
sorry, items.Clear
with calc do
begin
  Items.Clear;
  if portLen > 1 then
    Items.add('text1');
  if portLen > 2 then
    Items.add('text2');
  end;
end;

Open in new window

0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 125 total points
ID: 35040372
If you want to check whether an item is already in the list, you can use indexof like this
with calc do
begin
  if (portLen > 1) and (Items.IndexOf(text1) < 0) then
    Items.add('text1');
  if (portLen > 2) and (Items.IndexOf(text2) < 0) then
    Items.add('text2');
  end;
end;

Open in new window

0
 

Author Closing Comment

by:keats88
ID: 35040467
Much easier solution than I expected. I should have figured there was a function like Clear out there.

[code]Clear;[/code]

The above worked just fine.
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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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