Solved

Coloured rows in check list box

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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