Solved

ListBox, how to?

Posted on 2013-12-11
4
319 Views
Last Modified: 2014-01-21
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
0
Comment
Question by:hidrau
4 Comments
 
LVL 25

Accepted Solution

by:
Sinisa Vuk earned 500 total points
Comment Utility
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
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
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
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
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
 
LVL 1

Author Closing Comment

by:hidrau
Comment Utility
thanks for the idea :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

18 Experts available now in Live!

Get 1:1 Help Now