Solved

Coloured rows in check list box

Posted on 2000-03-28
4
214 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 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month6 days, 11 hours left to enroll

636 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