Solved

Delphi combobox list items refresh/delete/match index

Posted on 2011-03-04
4
1,901 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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