老問題 dbgrid Cursor 不見了 |
尚未結案
|
ROLAND168
一般會員 發表:39 回覆:49 積分:17 註冊:2003-02-26 發送簡訊給我 |
|
channel
尊榮會員 發表:67 回覆:707 積分:854 註冊:2002-05-02 發送簡訊給我 |
引言: 請教各位: 我的 dbgrid 進入儲存格內 Cursor 不見了!!參考過 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=28513 在 onEnter Events 加入 PostMessage( DBGrid1.Handle, WM_LBUTTONDOWN, 0, 0 ); postMessage( DBGrid1.Handle, WM_LBUTTONUp, 0, 0 ); 還是沒用?? 不知為何請教各位!!謝謝!!您只要將DBGrid的屬性Options/dgAlwaysShowEditor設為True即可,不須要下任何程式。 或參考這篇文章:
------
~小弟淺見,參考看看~ |
ROLAND168
一般會員 發表:39 回覆:49 積分:17 註冊:2003-02-26 發送簡訊給我 |
|
pedro
尊榮會員 發表:152 回覆:1187 積分:892 註冊:2002-06-12 發送簡訊給我 |
|
channel
尊榮會員 發表:67 回覆:707 積分:854 註冊:2002-05-02 發送簡訊給我 |
|
Justmade
版主 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
參看以前的討論 :
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=28307 那個問題結案後發現還有情況會使 Cursor 不出現
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=28398 後來才使用 PostMessage 模擬按滑鼠鍵的。 這個問題比較怪,做了某些設定 (如 Channel 兄提議的 dgAlwaysShowEditor, 其實在上文早已試過) 便會在某些情況下可行但另一些情況下不行。到目前為止使用 PostMessage 的方法我試過無論按滑鼠進出,Tab 進去,程式使用 SetFocus 都可行,除非你沒放對 PostMessage 使之跟本沒執行。但我不敢說這是所有情況都可行因可能只是我沒遇到不行的情況。 ROLAND168, 你想想若你不貼出你的程式碼(最好做一簡例上傳),別人甚猜到你是甚麼不行呢,若答題者答你是行的但不寫甚樣才行你會滿意嗎?
|
ROLAND168
一般會員 發表:39 回覆:49 積分:17 註冊:2003-02-26 發送簡訊給我 |
引言: ROLAND168, 你想想若你不貼出你的程式碼(最好做一簡例上傳),別人甚猜到你是甚麼不行呢,若答題者答你是行的但不寫甚樣才行你會滿意嗎?Sorry !! 因我有 77 個 form 有此 dbGrid 但有問題的只有 15個,原因不 明,但重啦就又可以了!!但我想知到原因為何,總不能每次重拉, 下列是我的 class="code">unit UDBGridu; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids,db,buttons; type TUDBGrid = class(TDBGrid) procedure DoExit;override; procedure DoEnter;override; procedure ColEnter;override; procedure ColExit;override; private { Private declarations } FIsEdit:boolean; procedure onExit(Sender: TObject); protected { Protected declarations } procedure KeyPress(var Key: Char); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override; public { Public declarations } function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override; published { Published declarations } property IsEdit:boolean read FIsEdit write FIsEdit; end; procedure Register; implementation procedure Register; begin RegisterComponents('Adm', [TUDBGrid]); end; { TSTDBGrid } procedure TUDBGrid.ColEnter; var vdsmaster,vObject,vnewbtn:Tcomponent; begin inherited; if (tdbgrid(self).Columns[SelectedIndex].ReadOnly) and (IsEdit) then begin if (SelectedIndex < fieldcount-1) and ((tdatasource(tdbgrid(self).datasource).state = dsEdit) or (tdatasource(tdbgrid(self).datasource).state = dsInsert)) then SelectedIndex:=SelectedIndex 1 else begin vobject:=TComponent(TComponent(self).Owner).FindComponent('sbSave'); vdsmaster:=TComponent(TComponent(self).Owner).FindComponent('dsMaster'); vnewbtn:=TComponent(TComponent(self).Owner).FindComponent('sbNew'); if (vObject <> nil) and (vdsMaster <> nil) and (vnewbtn <> nil) then begin case tdatasource(tdbgrid(self).datasource).state of dsEdit : begin TSpeedButton(vObject).Click; SelectedIndex:=0; end; dsInsert: begin TSpeedButton(vObject).Click; SelectedIndex:=0; TSpeedButton(vnewbtn).Click; end; end; end else messagedlg('dbnMaster Post error(TUDBGRID)',mtError,[mbOK],0); end; end; end; |
ROLAND168
一般會員 發表:39 回覆:49 積分:17 註冊:2003-02-26 發送簡訊給我 |
procedure TUDBGrid.ColExit; var vdsmaster,vObject,vnewbtn:Tcomponent; begin inherited; if (IsEdit) then begin if (SelectedIndex = fieldcount-1) and ((tdatasource(tdbgrid(self).datasource).state = dsEdit) or (tdatasource(tdbgrid(self).datasource).state = dsInsert)) then begin vobject:=TComponent(TComponent(self).Owner).FindComponent('sbSave'); vdsmaster:=TComponent(TComponent(self).Owner).FindComponent('dsMaster'); vnewbtn:=TComponent(TComponent(self).Owner).FindComponent('sbNew'); if (vObject <> nil) and (vdsMaster <> nil) and (vnewbtn <> nil) then begin case tdatasource(tdbgrid(self).datasource).state of dsEdit:TSpeedButton(vObject).Click; dsInsert: begin TSpeedButton(vObject).Click; TSpeedButton(vnewbtn).Click; end; end; end else messagedlg('dbnMaster Post error(TUDBGRID)',mtError,[mbOK],0); end; end; end; procedure TUDBGrid.DoEnter; begin inherited; ColEnter; end; procedure TUDBGrid.DoExit; begin inherited; end; function TUDBGrid.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; begin if WheelDelta < 0 then datasource.dataset.next; if WheelDelta > 0 then datasource.dataset.Prior; end; procedure TUDBGrid.KeyDown(var Key: Word; Shift: TShiftState); var oldselect,i:integer; begin if (IsEdit) then begin oldselect:=SelectedIndex; if (shift = [ssCtrl]) and (key = vk_delete) then key:=word (#0); if (tdatasource(tdbgrid(self).datasource).state=dsEdit) or (tdatasource(tdbgrid(self).datasource).state=dsInsert) then begin case key of VK_HOME,vK_END,SB_PAGEUP,SB_PAGEDOWN,vk_tab:key:=word(#0); vk_Up : begin if SelectedIndex > 0 then begin i:=1; while Columns[SelectedIndex-i].ReadOnly do begin i := i 1; if SelectedIndex-i < 0 then exit; end; if (SelectedIndex-i < 0) then SelectedIndex:=oldselect else SelectedIndex:=SelectedIndex-i; end; key:=word(#0); end; vk_Down: begin if SelectedIndex |
ROLAND168
一般會員 發表:39 回覆:49 積分:17 註冊:2003-02-26 發送簡訊給我 |
[code] procedure TUDBGrid.ColExit; var vdsmaster,vObject,vnewbtn:Tcomponent; begin inherited; if (IsEdit) then begin if (SelectedIndex = fieldcount-1) and ((tdatasource(tdbgrid(self).datasource).state = dsEdit) or (tdatasource(tdbgrid(self).datasource).state = dsInsert)) then begin vobject:=TComponent(TComponent(self).Owner).FindComponent('sbSave'); vdsmaster:=TComponent(TComponent(self).Owner).FindComponent('dsMaster'); vnewbtn:=TComponent(TComponent(self).Owner).FindComponent('sbNew'); if (vObject <> nil) and (vdsMaster <> nil) and (vnewbtn <> nil) then begin case tdatasource(tdbgrid(self).datasource).state of dsEdit:TSpeedButton(vObject).Click; dsInsert: begin TSpeedButton(vObject).Click; TSpeedButton(vnewbtn).Click; end; end; end else messagedlg('dbnMaster Post error(TUDBGRID)',mtError,[mbOK],0); end; end; end; procedure TUDBGrid.DoEnter; begin inherited; ColEnter; end; procedure TUDBGrid.DoExit; begin inherited; end; function TUDBGrid.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; begin if WheelDelta < 0 then datasource.dataset.next; if WheelDelta > 0 then datasource.dataset.Prior; end; procedure TUDBGrid.KeyDown(var Key: Word; Shift: TShiftState); var oldselect,i:integer; begin if (IsEdit) then begin oldselect:=SelectedIndex; if (shift = [ssCtrl]) and (key = vk_delete) then key:=word (#0); if (tdatasource(tdbgrid(self).datasource).state=dsEdit) or (tdatasource(tdbgrid(self).datasource).state=dsInsert) then begin case key of VK_HOME,vK_END,SB_PAGEUP,SB_PAGEDOWN,vk_tab:key:=word(#0); vk_Up : begin if SelectedIndex > 0 then begin i:=1; while Columns[SelectedIndex-i].ReadOnly do begin i := i 1; if SelectedIndex-i < 0 then exit; end; if (SelectedIndex-i < 0) then SelectedIndex:=oldselect else SelectedIndex:=SelectedIndex-i; end; key:=word(#0); end; vk_Down: begin if SelectedIndex |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |