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

x
?
Solved

Coloured rows in check list box

Posted on 2000-03-28
4
Medium Priority
?
216 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
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

971 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