delphi学习点滴——DBGrid的实用技巧
来源:互联网 发布:软件监理费用 编辑:程序博客网 时间:2024/06/14 00:00
1.隔行不同颜色显示
with TDBGrid(Sender) do
begin
if (gdSelected in State) or (gdFocused in State) then
Canvas.Brush.Color := clAqua
else if DataSource.DataSet.RecNo mod 2 = 0 then
Canvas.Brush.Color := $00F0F0F5
else
Canvas.Brush.Color := clWindow;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
2.Flat风格
属性设置:
Ctrl3D = False
Options.dgColLines = False
Options.dgRowLines = False
type
TGridAccess = class(TCustomGrid);
Form.OnCreate:
with TGridAccess(DBGrid1) do
Options := Options + [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine];
3.去掉滚动条
private
{ Private declarations }
FGridWndProc: TWndMethod;
procedure GridWndProc(var Message: TMessage);
Form.OnCreate:
TGridAccess(DBGrid1).ScrollBars := ssNone;
FGridWndProc := DBGrid1.WindowProc;
DBGrid1.WindowProc := GridWndProc;
Form.OnDestroy:
DBGrid1.WindowProc := FGridWndProc;
procedure TForm1.GridWndProc(var Message: TMessage);
begin
case Message.Msg of
WM_PAINT, WM_NCPAINT:
begin
SetScrollRange(DBGrid1.Handle, SB_HORZ, 0, 0, False);
SetScrollRange(DBGrid1.Handle, SB_VERT, 0, 0, False);
end;
end;
FGridWndProc(Message);
end;
4.鼠标移到某个单元格,指针形状改变
procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
Coord: TGridCoord;
begin
Coord := TDBGrid(Sender).MouseCoord(X, Y);
if (Coord.Y > 0) and (Coord.X = 1) and not TDBGrid(Sender).DataSource.DataSet.IsEmpty then
begin // Coord.X=1,dgIndicator=True时说明在第一列,False时说明在第二列
TDBGrid(Sender).Cursor := crHandPoint;
StatusBar1.SimpleText := 'Click to open curve form';
end
else
begin
TDBGrid(Sender).Cursor := crDefault;
StatusBar1.SimpleText := '';
end;
end;
5.Options.dgRowSelect=True时,点击不同单元格列,执行不同的动作
DBGrid的OnMouseDown/OnMouseUp事件在点击记录单元格时不会触发(点击固定行列区会触发),而Options.dgRowSelect=True时,OnCellClick事件的Column总是传递第一个列对象,即Column.Index=0,即使你点击的是其他列,因此需要在OnCellClick中再判断点击的是哪个列,再根据不同列执行不同的动作。
procedure TForm1.DBGrid1CellClick(Column: TColumn);
var
Coord: TGridCoord;
P: TPoint;
begin
GetCursorPos(P);
Windows.ScreenToClient(TDBGrid(Sender).Handle, P);
Coord := TDBGrid(Sender).MouseCoord(P.X, P.Y);
if (Coord.Y > 0) and (Coord.X = 1) and not TDBGrid(Sender).DataSource.DataSet.IsEmpty then
// Coord.X=1,dgIndicator=True时说明在第一列,False时说明在第二列
ShowMessage(GridRate.Columns[0].Field.AsString);
end;
- delphi学习点滴——DBGrid的实用技巧
- DBGrid的实用技巧
- DBGrid的实用技巧
- delphi学习点滴——编写自己的可视化控件
- delphi学习点滴——类似query的实
- delphi学习点滴—dbgrideh一个技巧
- delphi学习点滴—exit、abort比较
- delphi学习点滴—几个关闭函数
- delphi学习点滴——窗体创建和释放
- delphi学习点滴——数据集过滤技巧
- delphi学习点滴——用AdoDataSet实现数据表的导入导出
- delphi学习点滴——异常处理的基本原则和方法
- delphi学习点滴——利用DDE实现同Word的交互
- delphi学习点滴——动态链接库两种调用方式的比较
- delphi学习点滴——使用Query控件的两个技巧
- delphi学习点滴——操作excel的几个控件使用说明
- 将 DbGrid查询内容的导出为Txt函数——Delphi
- delphi学习点滴(二)
- Qt 中文显示 QMessageBox按钮中文显示
- 如何学习技术?
- 第十六周实验报告2
- delphi学习点滴——将数据库数据快速导入Excel
- android graphics画图的点击事件处理
- delphi学习点滴——DBGrid的实用技巧
- JAVA经典算法40题
- 16周1
- delphi学习点滴——使用Query控件的两个技巧
- 二分查找法
- JS的正则表达式对象使用方法 如何定义
- 快排
- dcc32.exe命令行编译工程搜索路径的问题
- 对象和数据库的天然阻抗