2014-02-17 17 views
2

當我將它放在MDIChildForm中時,我得到了一個DbGrid焦點錯誤。對MDI的DBGrid焦點錯誤

要reprocedure錯誤:

  • 創建MDI應用
  • 在主要形式,把面板,裏面
  • 一個編輯創建MDI子窗體
  • 將一個DBGrid和分配數據(超過1條記錄)

dbgrid focus bug on mdi

現在,運行應用程序,並按照步驟:

  • 單擊格,集中在第一排
  • 單擊編輯,重點是
  • 現在嘗試點擊另一行dbgrid。

錯誤:

  • 的DBGrid的不接收焦點,沒什麼happends!

我使用Delphi 7

有人可以幫我一個解決方法嗎?

回答

2

該問題由Form.ActiveControl創建。

在這種情況下,MDI子項在Edit focus後保留DBGrid作爲活動控件,並且因此在單擊dbgrid後未調用Windows.SetFocus。

我通過重寫TDBGrid.SetFocus解決的問題:

type 
    TMyDBGrid = class(TDBGrid) 
    public 
     procedure SetFocus; override; 
    end; 

procedure TMyDBGrid.SetFocus; 
var 
    form: TCustomForm; 
begin 
    inherited; 

    // BUG-FIX: force the SetFocus if the current Control is Self but not focused! 
    form := GetParentForm(Self); 
    if (form <> nil) and (form.ActiveControl = Self) and not Focused then 
    Windows.SetFocus(Self.Handle); 
end; 
+1

+1很好找到。但我會調查一個更一般的解決方案,因爲這個bug不僅適用於DBGrid的。 – NGLN

0

我通過將線

self.setfocus2 

事件OnShow解決了這個問題。我還將此代碼添加到OnActivate事件中。它現在完美。