DELPHI中的三方控件DBGRIDEH,怎么实现拉动鼠标选中多行,汇总选中的记录。就像EXCEL一样实现汇总功能
解决方案 »
- 困惑我很久的递归文件遍历的一个疑问, 大家帮忙看看吧. 谢谢了
- 需要delphi5.0,急急急!
- 关于delphi快速导入excel的问题
- Dephi7 与SQL2000的连接问题(translation Error. Error:10019)
- class TMemo not found
- 为什么一个简单的NMUDP例子运行不了了,请指点一下
- 按住label拖动就象按住标题一样可以拖动,怎么实现?
- 有没有能做出IE工具栏样式的控件,显示不完的按钮放在最右边的下拉菜单中?(除了Toolbar2000)
- 现在的计算机书籍实在是太贵了,于是想下载书看,不知拿电脑看书的效果如何啊?
- 求DLL与调用进程互通数据方法(很多的,什么类型都有),在最好有人能详细说说
- 请问如何分析文本数据
- 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;