Solved

Delphi combobox list items refresh/delete/match index

Posted on 2011-03-04
4
1,838 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
  • 3
4 Comments
 
LVL 32

Accepted Solution

by:
ewangoya 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:ewangoya
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:ewangoya
ewangoya 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now