关于DbGridEh的多选问题

2days 2003-08-04 04:23:48
我设置了DbGridEh的Option的DgMultiSelect为True; dgRowSelect为False

我如何知道,我选择了哪些行?
...全文
530 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoutian618 2003-08-05
  • 打赏
  • 举报
回复

gstRecordBookmarks:
begin
ColList := VisibleColumns;
for i := 0 to Selection.Rows.Count-1 do
begin
Bookmark := Selection.Rows[I];
end;
end;
zhoutian618 2003-08-05
  • 打赏
  • 举报
回复
你自己去分析吧。

大概的意思就是把选择的内容拷贝出来。
有三种:框选一部门,单击选择N行,单击选择N列。

gstRecordBookmarks块是你要的。
自己看吧。
zhoutian618 2003-08-05
  • 打赏
  • 举报
回复
不能以上的方法!
我写了一个:
function GetSelectedDataByRow(DBGEh: TDBGridEh; QryDest: TQuery;
ColName: string; ColSize: Integer; ValName: string; FixedCols: TStrings): Boolean;
function GetFieldSQLs: string;
function GetFieldSQL(FieldName: string): string;
var
tmp: TField;
n: Integer;
begin
tmp:=DBGEh.DataSource.DataSet.FindField(FieldName);
Result:='['+FieldName+']=';
if tmp=nil then
begin
Result:=Result+''''+StrN(' ', 100)+'''';
Exit;
end;
case tmp.DataType of
ftDateTime:
Result:=Result+'GetDate()';
ftFloat, ftCurrency:
Result:=Result+'9999999999.999';
ftSmallInt, ftInteger, ftWord:
Result:=Result+'9999999999';
ftBoolean:
Result:=Result+'CONVERT(BIT,0)';//仅SQL Server中有用
else
begin
n:=tmp.Size;
if n<=0 then n:=30;
Result:=Result+''''+StrN(' ', n)+'''';
end;
end;
end;
var
i: Integer;
tmpStr: string;
begin
Result:='';
if FixedCols<>nil then
for i:=0 to FixedCols.Count-1 do
begin
tmpStr:=GetFieldSQL(FixedCols[i]);
if tmpStr='' then Continue;
if i=0 then
Result:='SELECT '+tmpStr
else
Result:=Result+', '+tmpStr;
end;
if (Result<>'') and (ColName<>'') then
begin
Result:=Result+', ['+ColName+']='''+StrN(' ', ColSize)+'''';
Result:=Result+', ['+ColName+'_D]='''+StrN(' ', ColSize)+'''';
Result:=Result+', ['+ValName+']=999999999.99';
end;
end;
procedure WriteRecord(ColList: TColumnsEhList);
var
i, j: Integer;
tmp: string;
begin
with DBGEh.DataSource.DataSet do
begin
for i:=0 to ColList.Count-1 do
begin
QryDest.Append;
for j:=FixedCols.Count-1 downto 0 do
begin
tmp:=FixedCols[j];
if FindField(tmp)=nil then
QryDest[tmp]:=''
else
QryDest[tmp]:=FieldByName(tmp).AsString;
end;
tmp:=ColList[i].FieldName;
QryDest[ColName]:=tmp;
QryDest[ColName+'_D']:=ColList[i].Title.Caption;
if FindField(tmp)=nil then
QryDest[ValName]:=0
else if FieldByName(tmp).DataType in [ftFloat, ftInteger, ftSmallInt, ftWord, ftAutoInc, ftCurrency] then
QryDest[ValName]:=FieldByName(tmp).AsFloat
else
QryDest[ValName]:=0;
QryDest.Post;
end;
end;
end;
var
tmpStr: string;
i: Integer;
ColList: TColumnsEhList;
ASelectionType: TDBGridEhSelectionType;
begin
Result:=False;
QryDest.SQL.Clear;
tmpStr:=GetFieldSQLs;
if tmpStr='' then Exit;
QryDest.SQL.Add(GetFieldSQLs);
QryDest.Active:=True;
while not QryDest.Eof do
QryDest.Delete;
ASelectionType:=DBGEh.Selection.SelectionType;
if ASelectionType = gstNon then Exit;
with DBGEh do
begin
with DataSource.Dataset do
begin
DisableControls;
SaveBookmark;
try
case ASelectionType of
gstRecordBookmarks:
begin
ColList := VisibleColumns;
for i := 0 to Selection.Rows.Count-1 do
begin
Bookmark := Selection.Rows[I];
WriteRecord(ColList);
end;
end;
gstRectangle:
begin
ColList := TColumnsEhList.Create;
try
for i := Selection.Rect.LeftCol to Selection.Rect.RightCol do
if Columns[i].Visible then
ColList.Add(Columns[i]);
Bookmark := Selection.Rect.TopRow;
while True do
begin
WriteRecord(ColList);
if CompareBookmarks(Pointer(Selection.Rect.BottomRow),Pointer(Bookmark)) = 0 then Break;
Next;
if Eof then Break;
end;
finally
ColList.Free;
end;
end;
gstColumns:
begin
ColList := Selection.Columns;
First;
while Eof = False do
begin
WriteRecord(ColList);
Next;
end;
end;
gstAll:
begin
ColList := VisibleColumns;
First;
while Eof = False do
begin
WriteRecord(ColList);
Next;
end;
end;
end;
finally
RestoreBookmark;
EnableControls;
end;
end;
end;
Result:=True;
end;
yesxwl 2003-08-04
  • 打赏
  • 举报
回复
dbGrid中的用法参考估计一样
选取的行都存在dbgrid1.selectrows中
for I;=0 to dbgrid1.selectrows.count-1 do
with Dbgrid1.datasource.dataset do
begin
gotobookmark(Pointer(DBgrid1.selectedrows[i]))
Memo1.lines.add(FieldByName('Name').asstring;
end;
大地精灵 2003-08-04
  • 打赏
  • 举报
回复
用BOOKMARK

5,388

社区成员

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

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