DataGrid滚动时当前记录不变
来源:互联网 发布:c语言中括号的用法 编辑:程序博客网 时间:2024/06/10 18:04
unit Unit1;
interface
{鼠标中键/滚动条/翻页操作时锁定Dbgrid的选定纪录不动
by jinjazz}
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids, DB, DBTables, StdCtrls;
type
TDBGrid = class(DBGrids.TDBGrid)
private
FOldGridWnd: TWndMethod;
SelectedRow: integer;
procedure NewGridWnd(var Message: TMessage);
protected
procedure DrawColumnCell(const Rect: TRect; DataCol: Integer;
Column: TColumn; State: TGridDrawState); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
public
constructor Create(AOwner: TComponent); override;
end;
type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TDBGrid }
constructor TDBGrid.Create(AOwner: TComponent);
begin
inherited;
Options := Options + [dgindicator];
Self.FOldGridWnd := Self.WindowProc;
Self.WindowProc := NewGridWnd;
SelectedRow := -1;
end;
procedure TDBGrid.NewGridWnd(var Message: TMessage);
var
IsNeg: Boolean;
begin
if Message.Msg = WM_MOUSEWHEEL then
begin
IsNeg := Short(Message.WParamHi) < 0;
if IsNeg then
SendMessage(Handle, WM_VSCROLL, SB_LINEDOWN, 0)
else
SendMessage(Handle, WM_VSCROLL, SB_LINEUP, 0)
end
else
Self.FOldGridWnd(Message);
end;
procedure TDbGrid.DrawColumnCell(const Rect: TRect; DataCol: Integer;
Column: TColumn; State: TGridDrawState);
begin
if SelectedRow=-1 then SelectedRow:=DataSource.DataSet.RecNo;
Color := clinfobk;
Options := Options + [dgRowSelect];
if ((State = [gdSelected]) or (State = [gdSelected, gdFocused])) then
begin
Canvas.Brush.color := Color;
Canvas.Font.Color := Font.Color;
end;
if DataSource.DataSet.RecNo = selectedRow then
Canvas.Brush.color := clRed; //当前行以红色显示,其它行使用背景的浅绿色
Canvas.pen.mode := pmmask;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
procedure TDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
var
Cell: TGridCoord;
begin
inherited;
if Button = mbLeft then
begin
selectedRow := DataSource.DataSet.RecNo;
repaint;
end;
end;
end.
- DataGrid滚动时当前记录不变
- DataGrid滚动时当前记录不变
- 使DataGrid支持鼠标滚轮滚动记录
- DataGrid支持鼠标滚轮滚动记录
- DataGrid当列宽超出当前宽度时,没有数据也恒有滚动条
- 页面刷新时让滚动条不变
- WinForm中的DataGrid控件在刷新后保持原滚动条位置不变
- 怎样使DataGrid支持鼠标滚轮滚动记录
- jquery easyui datagrid js获取记录数 页数 当前页
- jquery easyui datagrid js获取记录数 页数 当前页
- jquery easyui datagrid js获取记录数 页数 当前页
- jquery easyui datagrid 获取当前页 记录数 总页数
- datagrid js获取记录数 页数 当前页
- jquery easyui datagrid js获取记录数 页数 当前页
- jquery easyui datagrid js获取记录数 页数 当前页
- jquery easyui datagrid js获取记录数 页数 当前页
- jquery easyui datagrid js获取记录数 页数 当前页
- jsp页面刷新时,保持滚动条位置不变
- FastStringFuncs(DelPhi 函數庫)
- DataGrid随鼠标滚动
- 如何在.Net中访问MySQL数据库
- 编程中的次要问题 --编程珠玑学习笔记 第五章
- DataGrid滚动时当前记录不变
- DataGrid滚动时当前记录不变
- 考勤术语及规则定制
- 网页焦点的移动
- 如何增加之后每 VisualC++ 中生成版本信息
- linux嵌入式编程高手历程系列5-初识linux网桥
- 在ASP.NET中打印表格
- asp 跟什么数据库搭配好啊?
- log4j相关属性简介
- 一个比日本还要傻x的国家诞生了 (是中国人的一定要看!!!愤怒!!!)