Delphi Grid Visible Item

时间:2010-10-13 07:28:54

标签: delphi grid delphi-7

全部,

我正在使用Delphi 7.我遇到了Grid问题。

我的网格有100行,之后我还要添加一些。例如,我选择的项目是1oth。网格一次在屏幕上显示20个项目。我将网格向下滚动。我到了最后一个。这里网格的Itemindex = 10;请注意,所选项目未显示在可见窗口中。当我添加项目时,网格刷新并移动以显示第10项。

我不想这样做。

我的要求是当添加新行时,屏幕应保持相同,如上次所示。

期待快速回复。

谢谢和问候,

VIJESH V.NAIR 系统分析师。 印度德里。

1 个答案:

答案 0 :(得分:0)

在添加项目书签之前,表格的当前行对应于dbgrid。 添加项目转到您的书签 使用TBookmark的示例: (您可以将tabledataset1替换为tableName,如table1)

unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, DBClient, ExtCtrls, ActnList, Grids, DBGrids,
  DBCtrls;

type
  TfrmMain = class(TForm)
    DataSource1: TDataSource;
    pnlClient: TPanel;
    pnlBottom: TPanel;
    btnFirst: TButton;
    btnLast: TButton;
    btnNext: TButton;
    btnPrior: TButton;
    DBGrid1: TDBGrid;
    ClientDataSet1: TClientDataSet;
    btnSetRecNo: TButton;
    DBNavigator1: TDBNavigator;
    btnGetBookmark: TButton;
    btnGotoBookmark: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btnNextClick(Sender: TObject);
    procedure btnLastClick(Sender: TObject);
    procedure btnSetRecNoClick(Sender: TObject);
    procedure btnFirstClick(Sender: TObject);
    procedure btnPriorClick(Sender: TObject);
    procedure btnGetBookmarkClick(Sender: TObject);
    procedure btnGotoBookmarkClick(Sender: TObject);
  private
    { Private declarations }
    FBookmark: TBookmark;
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  ClientDataSet1.LoadFromFile('C:\Employee.cds');
end;

procedure TfrmMain.btnFirstClick(Sender: TObject);
begin
  ClientDataSet1.First;
end;

procedure TfrmMain.btnPriorClick(Sender: TObject);
begin
  ClientDataSet1.Prior;
end;

procedure TfrmMain.btnNextClick(Sender: TObject);
begin
  ClientDataSet1.Next;
end;

procedure TfrmMain.btnLastClick(Sender: TObject);
begin
  ClientDataSet1.Last;
end;

procedure TfrmMain.btnSetRecNoClick(Sender: TObject);
var
  Value: string;
begin
  Value := '1';
  if InputQuery('RecNo', 'Enter Record Number', Value) then
    ClientDataSet1.RecNo := StrToInt(Value);
end;

procedure TfrmMain.btnGetBookmarkClick(Sender: TObject);
begin
  if Assigned(FBookmark) then
    ClientDataSet1.FreeBookmark(FBookmark);

  FBookmark := ClientDataSet1.GetBookmark;
end;

procedure TfrmMain.btnGotoBookmarkClick(Sender: TObject);
begin
  if Assigned(FBookmark) then
    ClientDataSet1.GotoBookmark(FBookmark)
  else
    ShowMessage('No bookmark set!');
end;

end.