当鼠标点第二行的某一格,整个第二行的颜色变成黄色,用来突出选的那格是第二行,当选第三或其它行,所选行变成黄色,第二行的颜色就变回原来的颜色,如何
编程,请写出程序
编程,请写出程序
解决方案 »
- 现场给分。。。一个表中的字段QTY,如果控制多次录入的QTY总的数量录入不超过一个数。。。。。
- 关于改变treeview 某些节点文本颜色的问题~~~帮帮忙
- Delphi中如何固定ListView的前几列
- 求一SQL,可以把一个字段中最大N个值和最小N个值去掉,在线结
- 抽奖程序我不会了请教!
- 怎样拦截指定的网址??
- 我那个快捷菜单popupMenu放在窗体上了。运行时。为什么不显示??
- 请教一个DLL兼容性的问题??? 100分
- 怎样将id和name信息同时放在combobox的下拉框中?
- fastreport制作成报表的能存进execl里吗?
- 有谁用过ExWise这个Wise的反编译工具。
- 经典搞笑
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, Grids, DBGrids;type
TMainForm = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Table1: TTable;
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;var
MainForm: TMainForm;implementation{$R *.dfm}procedure TMainForm.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if gdSelected in State then
begin
DBGrid1.Canvas.Brush.Color := clYellow ;
DBGrid1.Canvas.Font.Color := clRed;
end
else
DBGrid1.Canvas.Brush.Color := clWhite; DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;end.
还有optionsEh的dghRowHighlight属性设为True
我做的另一效果又不行
用StringGrid试试。
Name Age Wage
张山 25 500
王武 57 1060
李市 30 520
刘牛 28 390---- 2、创建基于TDBGrid的TColoredDBGrid组件
---- 在Delphi组件菜单中,选择New Component,在弹出对话框中作以下设置: Ancestor Type = TDBGrid
Class Name = TColoredDBGrid---- 然后单击OK按钮,Delphi自动完成组件基本框架的定义。增添OnDRawColoredDBGrid事件并使它出现在Object Inspector的Events中以便在应用程序中设定改变行颜色的条件。重载DrawCell方法,只能自己绘制单元格。不能通过在OnDrawColumnCell来设置颜色,因为在OnDrawColumnCell改变单元格的颜色会再次触发OnDrawColumnCell。
---- 下面就是所创建组件的源程序 。 ---- 3、建立应用程序进行验证。 ---- 在Delphi文件菜单中选择New建立新的应用程序工程Project1和主窗体Form1,设置Form1的Caption属性为“控制DBGrid行颜色的示例”。在主窗体上添加Data Source、Table、Button和ColoredDBGrid组件。设置各组件的属性如下: Table1.Database=’DBDemos’
Table1.Tablename=’example.db’
Datasource1.Dataset=Table1
ColoredDBGrid1.Datasource=DataSource1
Button1.Caption=’退出’---- 在ColoredDBGrid1的onDRawColoredDBGrid事件中输入下列代码,设定由Wage(工资)来决定在ColoredDBGrid1各行的颜色。
procedure TForm1.ColoredDBGrid1 DRawColoredDBGrid
(Sender: TObject; Field: TField; var Color:
TColor; var Font: TFont);
Var
p : Integer;
begin
p := Table1.FindField('wage').AsInteger;
//取得当前记录的Wage字段的值。
if(p < 500) then begin
//程序将根据wage值设置各行的颜色。
Color := clGreen;
Font.Style := [fsItalic];
//不仅可以改变颜色,还可以改变字体
end;
if(p >= 500) And (p < 800) then
Color := clRed;
if(p >=800) then begin
Color := clMaroon;
Font.Style := [fsBold];
end;
end;
//用‘退出’按钮结束程序运行。
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;---- 4、程序运行结果
得到预计的结果:第一行和第三行变为红色,第二行变为棕色,第四行为绿色,满足了基本要求。
with TCustomDBGridCracker(sender) do begin
begin
if (DataSource.DataSet.RecNo )=1 then
canvas.brush.color:=clblue;
canvas.Font.Style:=[];
canvas.Font.Size :=9;
canvas.Font.Color :=clblack;
end;
defaultdrawcolumncell(Rect,DataCol,Column,State);