全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1371
推到 Plurk!
推到 Facebook!

老問題 dbgrid Cursor 不見了

尚未結案
ROLAND168
一般會員


發表:39
回覆:49
積分:17
註冊:2003-02-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-07-01 18:01:19 IP:61.229.xxx.xxx 未訂閱
請教各位: 我的 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 ); 還是沒用?? 不知為何請教各位!!謝謝!!
channel
尊榮會員


發表:67
回覆:707
積分:854
註冊:2002-05-02

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-07-02 13:17:14 IP:211.21.xxx.xxx 未訂閱
引言: 請教各位: 我的 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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-07-03 04:57:46 IP:61.229.xxx.xxx 未訂閱
引言: 您只要將DBGrid的屬性Options/dgAlwaysShowEditor設為True即可,不須要下任何程式。 或參考這篇文章: >< face="Verdana, Arial, Helvetica"> 設了還是不行??
pedro
尊榮會員


發表:152
回覆:1187
積分:892
註冊:2002-06-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-07-03 09:00:54 IP:210.61.xxx.xxx 未訂閱
我試了一下, 拉了Table,DataSource,DBGrid 並串接好相對應屬性, 並沒有發現DBGrid Cell游標不見情形, 是不是有別的地方出錯, 才會讓您的Cursor不見了?
channel
尊榮會員


發表:67
回覆:707
積分:854
註冊:2002-05-02

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-07-03 09:36:21 IP:211.21.xxx.xxx 未訂閱
引言: 設了還是不行?? < face="Verdana, Arial, Helvetica"> 不太可能吧! 您再試一次可以嗎? <> <>> <>在> <>將> 小弟是用
------
~小弟淺見,參考看看~
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-07-03 10:24:32 IP:218.16.xxx.xxx 未訂閱
參看以前的討論 : 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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-07-03 12:04:32 IP:61.229.xxx.xxx 未訂閱
引言: 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

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-07-03 12:21:22 IP:61.229.xxx.xxx 未訂閱
 
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

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-07-03 12:22:55 IP:61.229.xxx.xxx 未訂閱
[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     
        
系統時間:2024-05-04 13:14:32
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!