Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delphi combobox list items refresh/delete/match index

Posted on 2011-03-04
4
Medium Priority
?
2,041 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:
Ephraim Wangoya earned 500 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 500 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

963 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