首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么在DBGrid中选择多个单元格,并在StatusBar中显示选中单元格的和

2012-04-10 
如何在DBGrid中选择多个单元格,并在StatusBar中显示选中单元格的和如题,请指教![解决办法]The following e

如何在DBGrid中选择多个单元格,并在StatusBar中显示选中单元格的和
如题,请指教!

[解决办法]
The following example copies the selected rows in a db grid to a list box.

procedure TForm1.Button1Click(Sender: TObject);
var
i, j: Integer;
s: string;
begin
if DBGrid1.SelectedRows.Count> 0 then
with DBGrid1.DataSource.DataSet do
for i:=0 to DBGrid1.SelectedRows.Count-1 do
begin
GotoBookmark(pointer(DBGrid1.SelectedRows.Items[i]));
for j := 0 to FieldCount-1 do
begin

if (j> 0) then s:=s+ ', ';
s:=s+Fields[j].AsString;
end;
Listbox1.Items.Add(s);
s:= ' ';
end;
end;
是不是要这,改一改就成求和的了
[解决办法]
The following example copies the selected rows in a db grid to a list box.

procedure TForm1.Button1Click(Sender: TObject);
var
i, j: Integer;
s: string;
begin
j:=0;
if DBGrid1.SelectedRows.Count> 0 then
with DBGrid1.DataSource.DataSet do
for i:=0 to DBGrid1.SelectedRows.Count-1 do
begin
GotoBookmark(pointer(DBGrid1.SelectedRows.Items[i]));
j:=j+DBGrid1.DataSource.DataSet[ '字段 '];
end;
StatusBar1.Panels[0].Text:=IntToStr(j);
end;

热点排行