TDBGrid에서 여러개의 래코드를 선택한후..
한번에 처리를 하려고 밑에 제가 올렸었던 소스를 이용해봤습니다..
TDBGrid의 Options 프로퍼티의 dgMultiSelect 값만 True로
설정해주고..
아래의 소스를 그대로 사용하시면 됩니다..
근데 우스운 것은.. DBGrid의 SelectedRows 프로퍼티가 분명히 존재함
에도 델파이 2.0의 도움말에서는 아무리 찾아봐도 찾을 수가 없다는 것
이죠.. (델파이 2.0의 도움말이 업그레이드가 되었네 하는 이야기를 들
은 것도 같은데..)
SelectedRows 프로퍼티는 TBookmarkList 형인데..
TBookmarkList 형 역시.. 도움말에선 찾을 수가 없네요..
(근데.. 3.0 도움말엔 나오네.. 흘흘..)
아래 TBookmarkList 형의 정의를 VCL 소스에서 찾아다 붙여 놓았습니
다.. 코딩하시는데 도움이 될 거여요..
기람..
미친병아리 서비였네용.. 삐약~ !!
procedure TForm1.SelectClick(Sender: TObject);
var
x: word;
TempBookmark: TBookMark;
begin
DBGrid1.Datasource.Dataset.DisableControls;
with DBgrid1.SelectedRows do
if Count > 0 then
begin
TempBookmark:= DBGrid1.Datasource.Dataset.GetBookmark;
for x:= 0 to Count - 1 do
begin
if IndexOf(Items[x]) > -1 then
begin
DBGrid1.Datasource.Dataset.Bookmark:= Items[x];
showmessage(DBGrid1.Datasource.Dataset.Fields[1].AsString);
end;
end;
end;
DBGrid1.Datasource.Dataset.GotoBookmark(TempBookmark);
DBGrid1.Datasource.Dataset.FreeBookmark(TempBookmark);
DBGrid1.Datasource.Dataset.EnableControls;
end;
TBookmarkList = class
private
FList: TStringList;
FGrid: TCustomDBGrid;
FCache: TBookmarkStr;
FCacheIndex: Integer;
FCacheFind: Boolean;
FLinkActive: Boolean;
function GetCount: Integer;
function GetCurrentRowSelected: Boolean;
function GetItem(Index: Integer): TBookmarkStr;
function Insert(const Item: TBookmarkStr): Integer;
procedure SetCurrentRowSelected(Value: Boolean);
procedure StringsChanged(Sender: TObject);
protected
function CurrentRow: TBookmarkStr; // shortcut to grid.datasource...
function Compare(const Item1, Item2: TBookmarkStr): Integer;
procedure LinkActive(Value: Boolean);
public
constructor Create(AGrid: TCustomDBGrid);
destructor Destroy; override;
procedure Clear; // free all bookmarks
procedure Delete; // delete all selected rows from dataset
function Find(const Item: TBookmarkStr; var Index: Integer): Boolean;
function IndexOf(const Item: TBookmarkStr): Integer;
function Refresh: Boolean;// drop orphaned bookmarks;
// True = orphans found
property Count: Integer read GetCount;
property CurrentRowSelected: Boolean read GetCurrentRowSelected
write SetCurrentRowSelected;
property Items[Index: Integer]: TBookmarkStr read GetItem; default;
end;
|