Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1793
  • Last Modified:

Hiding Items in Listbox

I'm trying to make a gui-search similar to winamp's jump feature. This requires me to hide items in the listbox. I looked, but I don't thing that a normal listbox has this features.

I'm thinking that I could make a second listbox and take items that 'passes' the search, to there. But this seams like a lot of work.

What's the easiest way?
0
Stream12
Asked:
Stream12
1 Solution
 
mocartsCommented:
you can keep all your items in TStringList and when searched, search in it and use ListBox to display results

var
  data: TStringList;
 
// returns search result in TStringList;
procedure PerformSearch(const Phrase: string; st: TStrings);
var i: integer;
begin
  st.BeginUpdate;
  try
    st.Clear;
    for i := o to data.Count -1 do
      if .. then
        st.Add(data[i]);
  finally
    st.EndUpdate;
  end;
end;

// without timer
procedure TForm1.Edit1Change(Sender: TObject);
begin
  PerformSearch(Edit1.Text, ListBox1.Items);
end;

// with timer
procedure TForm1.Edit1Change(Sender: TObject);
begin
  Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  PerformSearch(Edit1.Text, ListBox1.Items);
end;

wbr, mo.
0
 
rayek007Commented:
You could try this "memo1.lines.clear;" every time you press a key in the edit or what you are using for the searched word, and the rest of your code.
0
 
nestoruaCommented:
HI,
If you wish to use only ListBox then the most natural and resonable way - to use TStringList and filter it then showing the filtered result in ListBox (as it's proposed above by mocarts).
If not - then you can use TClientdataSet and TDBGrid, they are lovely do that filtering you need and show result in different ways.
Sincerely,
Nestorua.
0
 
Stream12Author Commented:
I had to change some things, but your anwser did help. Thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now