Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Coloured rows in check list box

Posted on 2000-03-28
4
Medium Priority
?
215 Views
Last Modified: 2010-08-05
I have a check list box component that displays a list of tasks to be completed.

I would like to be able to change the colour of a line if it has been active for more than 4 hours, but can't find a way to change 1 row's font attributes without changing every row.

Any ideas?
0
Comment
Question by:johnstoned
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:aubs
ID: 2663464
Use the ondrawitem event to change the font color for a particular line
0
 
LVL 2

Accepted Solution

by:
aubs earned 400 total points
ID: 2663502
Set the CheckListBox Style property to lbOwnerDrawFixed.


Then put this in the OnDrawItem Event. It should show you how you can change the font color.

procedure TMainForm.CheckListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  Offset: integer;
begin
      with (Control as TCheckListBox).Canvas do
      begin
        Offset:= 6; //maynot be needed
            FillRect(Rect);
        if (Control as TCheckListBox).Checked[Index] then
              (Control as TCheckListBox).font.Color:= clRed
        else
          (Control as TCheckListBox).font.Color:= clBlack;
            TextOut(Rect.Left + Offset, Rect.Top, (Control as TCheckListBox).Items[Index]) ;
      end;

end;
0
 

Author Comment

by:johnstoned
ID: 2664425
This bit of code seemed to have a bug.  It keeps flashing the items up in the screen then redrawing them again.

if (Control as TCheckListBox).Checked[Index] then
   (Control as TCheckListBox).font.Color:= clRed
   else
     (Control as TCheckListBox).font.Color:= clBlack;


After a little experimentation, I changed

Control as TCheckListBox).font.Color:= clRed
to
font.Color:= clRed
and that seemed to cure it.

Thanks for the help.
0
 

Author Comment

by:johnstoned
ID: 2664426
This bit of code seemed to have a bug.  It keeps flashing the items up in the screen then redrawing them again.

if (Control as TCheckListBox).Checked[Index] then
   (Control as TCheckListBox).font.Color:= clRed
   else
     (Control as TCheckListBox).font.Color:= clBlack;


After a little experimentation, I changed

Control as TCheckListBox).font.Color:= clRed
to
font.Color:= clRed
and that seemed to cure it.

Thanks for the help.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

730 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