ListBox, how to?

Hello Guys,

I need a clue how to do something like this:

I have a lisbox on my form with 20 lines, some lines are painted in color font clRed and other clblack.

How can I count how many lines I have in my listbox in clred color font?

Thanks
Alex
LVL 1
hidrauAsked:
Who is Participating?
 
Sinisa VukCommented:
Each listbox item is stored in TStrings list. Item can be stored in with some additional parameter as TObject (integer, like Tcolor is integer too):
listbox.Items.AddObject('item in red', TObject(clRed));
listbox.Items.AddObject('item in red', TObject(clBlack));
....

Open in new window


later you can check for this additional parameter (and even check when drawing in some of OnDraw events):
for i:=0 to listbox.Items.Count-1 do
begin
  if listbox.Items.Objects[i] = TObject(clRed) then ...
  if listbox.Items.Objects[i] = TObject(clBlack) then
end;

Open in new window

0
 
MerijnBSr. Software EngineerCommented:
How did the items become red? Probably because you painted them red? From what information did you decide to make them red? Can't you look in that information to count?
0
 
Geert GOracle dbaCommented:
or the other way around:

how did you paint them black > the_number_of_blacks
to find the reds: listbox.count - the_number_of_blacks
0
 
hidrauAuthor Commented:
thanks for the idea :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.