如何样设置TDBGRID 当前行某字段的焦点
推荐于2016-09-19 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517183
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
怎么样设置TDBGRID 当前行某字段的焦点?
[解决办法]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls;
type
TForm1 = class(TForm)
ADODataSet1: TADODataSet;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
ADODataSet1.FieldDefs.Add( 'F1 ', ftString, 20);
ADODataSet1.FieldDefs.Add( 'F2 ', ftString, 20);
ADODataSet1.CreateDataSet;
ADODataSet1.Open;
for i := 1 to 100 do
ADODataSet1.AppendRecord([inttostr(i), 'data ']);
ADODataSet1.First;
DBGrid1.Options := DBGrid1.Options + [dgAlwaysShowSelection];
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ADODataSet1.Locate( 'F1 ', '66 ', [loCaseInsensitive]);
DBGrid1.SelectedIndex := 1;
end;
end.
[解决办法]
procedure TForm1.Button1Click(Sender: TObject);
begin
DBGrid1.Fields[5].FocusControl;// Fields[5]就是第6列
DBGrid1.SetFocus;
end;
[解决办法]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls;
type
TForm1 = class(TForm)
ADODataSet1: TADODataSet;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
ADODataSet1.FieldDefs.Add( 'F1 ', ftString, 20);
ADODataSet1.FieldDefs.Add( 'F2 ', ftString, 20);
ADODataSet1.CreateDataSet;
ADODataSet1.Open;
for i := 1 to 100 do
ADODataSet1.AppendRecord([inttostr(i), 'data ']);
ADODataSet1.First;
DBGrid1.Options := DBGrid1.Options + [dgAlwaysShowSelection];
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ADODataSet1.Locate( 'F1 ', '66 ', [loCaseInsensitive]);
DBGrid1.SelectedIndex := 1;
end;
end.
[解决办法]
procedure TForm1.Button1Click(Sender: TObject);
begin
DBGrid1.Fields[5].FocusControl;// Fields[5]就是第6列
DBGrid1.SetFocus;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询