DELPHI中的三方控件DBGRIDEH,怎么实现拉动鼠标选中多行,汇总选中的记录。就像EXCEL一样实现汇总功能
解决方案 »
- 提一个delphi的问题,附上源码,请高手指点下(短)
- 高手请进,再问Richedit透明问题
- 帮帮我吧~!刚学 实在是不会啊!
- 问一个有关ADO操作ACCESS视图的问题
- 关于ADOQuery的LoadFromFile方法的一个问题
- 请问各位哪里有下载report builder?麻烦,因为急用
- 我调试程序时,设断点一按F8就弹出CPU窗口是咋回事,程序正常,是delphi设置的问题
- 哪里有收费的demo程序供学习借鉴?
- 100分求教 exitthread的用法。在线等待,立即给分。
- QReport组件版上的QuickRep在打印预览时数据显示错误?
- 请问如何分析文本数据
- Filter过滤access的中文字符串问题
http://blog.csdn.net/apple_1987/archive/2009/01/10/3746606.aspx
楼主要的是这个吗?
OnMouseUP(...)
var isum:integer;
begin
i:=0;
if DBGrid1.SelectedRows.Count>0 then
for i:=0 to DBGrid1.SelectedRows.Count-1 do
begin
GotoBook(pointer(DBGrid1.SelectedRows.Items[i]));//
isum = isum + DBGrid1.DataSource.DataSet.fields[2].asinteger;
end;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, GridsEh, DBGridEh, StdCtrls, DB, DBClient;type
TForm1 = class(TForm)
DataSource1: TDataSource;
ClientDataSet1: TClientDataSet;
DBGridEh1: TDBGridEh;
procedure FormCreate(Sender: TObject);
procedure DBGridEh1SelectionChanged(Sender: TObject);
private
procedure GetTotal;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
I: integer;
begin
with ClientDataSet1 do
begin
with FieldDefs.AddFieldDef do
begin
DataType := ftString;
Size := 10;
Name := 'Field1';
end; with FieldDefs.AddFieldDef do
begin
DataType := ftInteger;
Name := 'Field2';
end; CreateDataSet; for I:=0 to 5 do
begin
Insert;
Fields[0].AsString := Chr(byte('A')+I);
Fields[1].AsInteger := I;
Post;
end;
end; DataSource1.DataSet := ClientDataSet1;
end;procedure TForm1.GetTotal;
var
Total: integer;
BM: TBookStr;
begin
with DBGridEh1 do
begin
if Selection.SelectionType<>gstRectangle then Exit;
with DataSource.DataSet do
begin
try
BM := Book;
DisableControls;
Book := Selection.Rect.TopRow;
while True do
begin
Total := Total + Columns[1].Field.AsInteger;
if CompareBooks(Pointer(Selection.Rect.BottomRow),Pointer(Book)) = 0 then Break;
Next;
if Eof then Break;
end;
finally
Book := BM;
EnableControls;
end;
end;
end;
DBGridEh1.Columns[1].Footers[0].Value := IntToStr(Total);
end;procedure TForm1.DBGridEh1SelectionChanged(Sender: TObject);
begin
Self.GetTotal;
end;end.
object Form1: TForm1
Left = 195
Top = 123
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGridEh1: TDBGridEh
Left = 120
Top = 96
Width = 337
Height = 257
DataSource = DataSource1
Flat = False
FooterColor = clWindow
FooterFont.Charset = DEFAULT_CHARSET
FooterFont.Color = clWindowText
FooterFont.Height = -11
FooterFont.Name = 'MS Sans Serif'
FooterFont.Style = []
FooterRowCount = 1
Options = [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit, dgMultiSelect]
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
OnSelectionChanged = DBGridEh1SelectionChanged
Columns = <
item
EditButtons = <>
FieldName = 'Field1'
Footers = <>
Width = 122
end
item
EditButtons = <>
FieldName = 'Field2'
Footers = <
item
Color = clYellow
ValueType = fvtStaticText
end>
Width = 130
end>
end
object DataSource1: TDataSource
DataSet = ClientDataSet1
Left = 80
Top = 112
end
object ClientDataSet1: TClientDataSet
Aggregates = <>
FieldDefs = <>
IndexDefs = <>
Params = <>
StoreDefs = True
Left = 80
Top = 152
end
end
能否发一份?谢谢
[email protected]
谢谢
ROWSELECT为TRUE时, Selection.SelectionType 为gstRecordBooks, 需要另外处理了。
procedure TForm1.GetTotal;
var
Total, I: integer;
BM: TBookStr;
begin
{ with DBGridEh1 do
begin
if Selection.SelectionType<>gstRecordBooks then Exit;
with DataSource.DataSet do
begin
try
BM := Book;
DisableControls;
Book := Selection.Rect.TopRow;
while True do
begin
Total := Total + Columns[1].Field.AsInteger;
if CompareBooks(Pointer(Selection.Rect.BottomRow),Pointer(Book)) = 0 then Break;
Next;
if Eof then Break;
end;
finally
Book := BM;
EnableControls;
end;
end;
end; } with DBGridEh1 do
begin
if Selection.SelectionType<>gstRecordBooks then Exit;
with DataSource.DataSet do
begin
try
BM := Book;
DisableControls;
Total := 0;
for I := 0 to Selection.Rows.Count-1 do
begin
Book := Selection.Rows[I];
Total := Total + VisibleColumns[1].Field.AsInteger
end;
finally
Book := BM;
EnableControls;
end;
end;
end; DBGridEh1.Columns[1].Footers[0].Value := IntToStr(Total);
end;