SMDBGRID 多筆選取刪除問題,懇請大家協助 |
尚未結案
|
g9221712
高階會員 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
我這樣寫錯了嗎? GotoBookmark(Pointer(SMDBGrid02.SelectedRows.Items[i])); 這個好像有問題
[code delphi] procedure TFRM_Main.MenuItem4Click(Sender: TObject); var i: integer; begin // SMDBGRID 多筆選取刪除紀錄 if Application.MessageBox('是否刪除呢?', '刪除確認', MB_YESNO MB_ICONQUESTION MB_DEFBUTTON2) = IDYES then begin if SMDBGrid02.SelectedRows.Count > 0 then begin with SMDBGrid02.DataSource.DataSet do begin DisableControls; // 加速畫面顯示 for i := 0 to SMDBGrid02.SelectedRows.Count - 1 do begin GotoBookmark(Pointer(SMDBGrid02.SelectedRows.Items[i])); Delete; end; EnableControls; end; end; end else begin Application.MessageBox('沒有選取紀錄,沒有動作!', '訊息提示', MB_OK MB_ICONWARNING); end; end; [/code]
------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」 程式寫的越久,卻發現自己越來越不會寫程式! |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
請參閱 Delphi Help (咦?還有這東西?)
[code delphi] procedure TForm1.Button1Click(Sender: TObject); var SavePlace: TBookmark; PrevValue: Variant; begin with Customers do begin { Get a bookmark, so that you can return to the same record. } SavePlace := GetBookmark; try { Move to previous record. } FindPrior; { Get the value. } PrevValue := FindField('Field2').Value; {Move back to the bookmark. It may not be the next record anymore, in the case when something else is changing the dataset asynchronously. } GotoBookmark(SavePlace); { Set the value. } Edit; FindField('Field2').Value := PrevValue; except ShowMessage('An error encountered'); end; end; end; { To ensure that the button is disabled when there is no previous record, the OnDataChange event of the DataSource detects when you move to the beginning of the file (the BOF property becomes True) and disables the button. Detection occurs on scrolling and editing, not on mouse selection. procedure TForm1.DS2DataChange(Sender: TObject; Field: TField); begin if Customers.Bof then Button1.Enabled := False else Button1.Enabled := True; end; [/code] |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |