DBGrid相关技术整理

DBGrid相关技术整理;

注:对于DBGrid相关属性、方法的学习融入到技术整理过程中

一,多选

设置属性:

  Options->dgMultiSelect = True;

->dgRowSelect   = True;

应用属性:

  SelectedRows;

操作方法:

-Ctrl + Mouse Clicks

-Shift + Arrow Keys

For example:

1,取得所选行某个字段的值的合计:

procedure TForm1.btnDoSumClick(Sender: TObject);

var

i: Integer;

sum: Single;

begin

if DBGrid1.SelectedRows.Count > 0 then

begin

sum := 0;

with DBGrid1.DataSource.DataSet do

begin

for i := 0 to DBGrid1.SelectedRows.Count - 1 do

begin

GotoBookmard(Pointer(DBGrid1.SelectedRows.Items[i]));

sum := sum + AdoQuery1.FieldByName('Size').asfloat;

end;

end;

edtSizeSum.Text := FloattoStr(sum);

end;

end;

//用edtSizeSum来接收计算来的合计值

2,全选DBGrid:

procedure DBGridSelectAll(AGrid: TDBGrid) ;

begin

AGrid.SelectedRows.Clear;

with AGrid.DataSource.DataSet do

begin

DisableControls;

First;

try

while not EOF do

begin

AGrid.SelectedRows.CurrentRowSelected := True;

Next;

end;

finally

EnableControls;

end;

end;

end;

深入了解:

1,SelectedRows:

The TDBGrid component keeps all the selections as Bookmarks in a TStringList,

and all the Bookmarks must be converted to a Pointer (what they really are) before using it.

&

The SelectedRows property is an object of type TBookmarkList.

We can use the SelectedRows property to, for example:

--get the number of rows selected,

--clear the selection(unselect),

--delete all the selected records,

--check whether a particular record is selected.

2,运行时设置DBGrid的多选属性

DBGrid1.Options := DBGrid1.Options + [dgMultiSelect];

//以上部分内容取自http://delphi.about.com/od/usedbvcl/l/aa032503a.htm

二,加入其它控件
http://delphi.about.com/od/usedbvcl/l/aa082003a.htm
http://delphi.about.com/od/usedbvcl/l/aa082003a.htm
三,颜色设置
http://delphi.about.com/od/usedbvcl/l/aa031699.htm

上一篇:C#进程间通讯技术-整理。


下一篇:为 HTTP/2 头压缩专门设计的 HPACK