我的意图是当记录中有报警时变成红色,断线时为黄色。但我在CustomDrawItem中加入代码。可是颜色并没像预期的那样改变,而是当窗体有变化时才变。大家帮我看看代码,到底哪儿有问题。
Var
  SensorType:String;
  WarnValue,CurValue:Real;
  SiteID,SensorID:Integer;
begin
  SiteID:=StrToIntDef(Copy(Trim(Item.Caption),1,2),1);
  SensorID:=StrToIntDef(Copy(Trim(Item.Caption),3,2),1);
  SensorType:=Copy(Trim(Item.Caption),5,1);
  ListViewAll.Canvas.Font.Color:=clBlack;
  if SensorType='A' then
    begin
      if SensorAInfo[SiteID][SensorID].Warned then
      begin
        if ListViewAll.Canvas.Font.Color<>clRed then
          begin
            ListViewAll.Canvas.Font.Color := clRed;
          end;
      end
        else
      if SensorAInfo[SiteID][SensorID].CurValue='未接' then
      begin
        if ListViewAll.Canvas.Font.Color<>clYellow then
          ListViewAll.Canvas.Font.Color := clYellow;
      end
        else
      begin
        if ListViewAll.Canvas.Font.Color<>clGreen then
          ListViewAll.Canvas.Font.Color := clGreen;
      end;
    end;
end;

解决方案 »

  1.   

    这肯定是你预期的情况下不能触发CustomDrawItem,你可以在预期的情况下写代码来触发CustomDrawItem。
      

  2.   

    uses
      CommCtrl;
    function ReDrawItem(HwndLV: HWND; ItemIndex: integer): boolean;
    begin
      Result := ListView_RedrawItems(HwndLV, ItemIndex, ItemIndex);
    end;//当记录中有报警时你就使用这句来重绘一条记录:
    ReDrawItem(ListView1.handle,Item.index);贴出的代码不用改了-------------------------------------------------------
    本回复由大傻的破玩意儿【CSDN's forum Explorer】完成!
    软件功能强大,速度超快!!支持中...
    软件下载地址:http://CoolSlob.ys168.com
      

  3.   

    TOO 楼上:
       你的方法不知道可以不,没试,但我觉得那样有点麻烦。
      

  4.   

    CSDN人气不旺啊,发个帖子根本没人看~!
      

  5.   

    应当是没有触发OnCustomDrawItem事件,在可能会触发的地方重绘一下Listview