我想实现的是单击一个按钮,这样根据用户选择的条件可能有查到几条数据,
该数据一定在一个以存在listview的记录中,我想在listview中让这几条记录改变颜色。 各位小弟拜托了
解决方案 »
- delphi中怎么实现象联众一样定时自动关闭的提示框
- 关于indy 中InudpServer与InUdpClient的用法
- 请问:是不是有现成的中文语音库,怎么调用TTS ???
- 如何实现监控某程序运行窗口内出现关键字后,关闭程序或是重启计算机?
- 求解:如何在dephi中调用*.chm格式的帮助文件,并且能直接定位到某一页
- 能够将Delphi的.Frm文件动态加入程序中吗?
- 函数或过程可以传递类吗?
- 怎么给已经有的unit重命名????????(牛虻)
- 有谁用Delphi做游戏!欢迎探讨!
- 如何在没有安装access的机器上,使用access建立的数据库,程序打包时需要哪些文件?
- 日期相减,得到相差的月份,有没有简单的方法啊?
- 很简单的问题,如何当输入回车时响应?
在ListView的OnCustomDrawItem事件里——procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
R: TRect;
begin
with Sender.Canvas do begin
R := Item.DisplayRect(drBounds);
if Item.Index mod 2 = 1 then begin//对奇数行改变底色和字体
Brush.Color := clTeal;
Font.Color := clYellow;
Font.Style := Font.Style + [fsBold];
DefaultDraw := False;
end;
if cdsSelected in State then begin
Brush.Color := clHighLight;
Font.Color := clHighLightText;
end;
FillRect(R);
TextRect(R, R.Left + 2, R.Top, Item.Caption);
end;
DefaultDraw := False;
end;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if Item.Caption = 'tommy' then //条件:)
(Sender as TListView).Canvas.Font.Color := clMaroon;
end;
var
i : integer;
begin
for i:=Listview1.Items.Count-1 Downto 0 do
begin
ListView1.Items[i].GetPosition;
SendMessage(Listview1.Handle, LVM_SETTEXTCOLOR, 0, clred);
ListView1.Repaint;
end;
end;
上面的是个范例。你可以通过查找到的item index值,或者caption来确定该item的position。
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
if Item.Caption<>'322' then
Sender.Canvas.Font.Color:=clRed;
end;
符合你给定条件的一些行,将Canvas的颜色变成其他颜色就可以了