怎么可以得到在DBGrid中选中的多行数据!

ruffian1052 2004-04-03 09:59:42
ShowMessage(DBGrid1.DataSource.DataSet.FieldByName('field_01').AsString);
or
ShowMessage(DBGrid1.DataSource.DataSet.Fields[0].AsString);

上面可以得到当前选中的数据!
怎么可以得到多选的那??
...全文
280 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lth1025 2004-08-12
  • 打赏
  • 举报
回复
DBGrid1.Options:= DBGrid1.Options+[dgTitles,dgIndicator,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgConfirmDelete,dgCancelOnExit,dgMultiSelect];

先在DBGrid1的Options属性中将以上几项设为True.

然后再看下面这段代码:

procedure TSBGZJHBMLDSPForm.tbPlspClick(Sender: TObject);
var
maxcount,j:integer;
begin
if RadioGroup2.ItemIndex=0 then
begin
if not Query1.IsEmpty then
begin
if DbgridEh1.SelectedRows.Count=0 then
begin
showmessage('请选择要批审的记录!前头框边颜色为黑色为选中.');
Exit;
end else
begin
if MessageBox(Handle,'你确定批量审批这些记录吗?','询问',
MB_ICONQUESTION+MB_YESNO)=mrYes then
begin
maxcount:=DbGridEh1.SelectedRows.Count - 1;
for j := 0 to DbgridEh1.SelectedRows.Count - 1 do
begin
maxcount:=DbgridEh1.SelectedRows.Count - 1;
with DbGridEh1.DataSource.DataSet do
begin
GotoBookmark(pointer(DBGridEh1.SelectedRows.Items[j]));
if Query1SPJG.Value='0' then
begin
Query1.Edit;
Query1SPSL1.Value:=Query1SL.Value;
Query1SPZJ1.Value:=Query1YSZJ.Value;
Query1SPJG.Value:='1';
//单项小于10万元的项目赋值下一级
if not ((Query1SPSL1.AsFloat=0) or (Query1SPSL1.AsFloat=null)) then
begin
if (Query1SPZJ1.AsFloat/Query1SPSL1.AsFloat<10) then
begin
Query1SPSL2.Value:=Query1SPSL1.Value;
Query1SPZJ2.Value:=Query1SPZJ1.Value;
end;
end;
Query1.Post;
Query1.ApplyUpdates;
Query1.CommitUpdates;
end;
end;
end;
showmessage('数据批量审批完毕!');
OpenQuery(Query1,Query1.SQL.Text);
Query1AfterScroll(Query1);
end;
end;
end;
end else
begin
showmessage('请选择未批的数据审批!');
exit;
end;
end;
THQ 2004-04-15
  • 打赏
  • 举报
回复
up~
我也想知道……
samcrm 2004-04-11
  • 打赏
  • 举报
回复
var
temp:TBookmarkstr;
xudaifei 2004-04-11
  • 打赏
  • 举报
回复
TO menggirl(看天上浮云,胜似闲庭信步) :

我也遇到同样的问题,我也是了你的方法,但是
BookMark 是 DataSet的一个proprety, 用Temp : bookMark时就会报错
menggirl 2004-04-03
  • 打赏
  • 举报
回复
var
temp:bookmark;
begin
for i:=0 to dbgrid.selecterows.count-1 do begin
temp:=dbgrid.selectrows.items[i];
table1.gotomark(temp);
for j:=0 to table.fieldcount-1 do
保存当前记录
table1.freebookmark(temp);
end;
即可处理
ruffian1052 2004-04-03
  • 打赏
  • 举报
回复
with DBGrid.Datasource.Dataset do
begin
if not Active then Abort;
DisableControls;
try
First;
while not EOF do
begin
if DBGrid.SelectedRows.CurrentRowSelected then
begin
\\do you want
end;
Next;
end;
finally
EnableControls;
end;
end;
ruffian1052 2004-04-03
  • 打赏
  • 举报
回复
呵呵~~谢谢了!!BOOKMARK好笼统的说法!详细点
ruffian1052 2004-04-03
  • 打赏
  • 举报
回复
with DBGrid.Datasource.Dataset do
begin
if not Active then Abort;
DisableControls;
try
First;
while not EOF do
begin
DBGrid.SelectedRows.CurrentRowSelected:=True;
Next;
end;
finally
EnableControls;
end;
end;
hmzgz81 2004-04-03
  • 打赏
  • 举报
回复
用Tbookmark

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧