一個軟體的成功除了跟軟體的靈活性和功能有很大關系之外,其實操作的便利性也占了很大一部分,特别是想搶占其他軟體的領域的時候。實施的成功與否跟操作者有着很大的關系,要直接使用者的認可,在資料的輸入方面就要花費很大的功夫了。
公司的項目都是用DBGridEH做從表資料的輸入,當一列設定為ReadOnly後,在Enter的時候自動的會跳過這個單元格。
由于我的架構裡面都使用的是cxGrid做輸入,cxGrid這樣做就不行,也許大家會想到設定column的Focusing屬性。這樣做是可以,但有個很不爽的問題(可能大家認為不是什麼問題)連複制都行,無法獲得焦點。經過跟蹤源碼。對代碼做了一些改動。主要是修改cxGridCustomTableView.pas這個檔案。如下:

代碼
1 //為了友善修改把相近的代碼也貼出來。
2
3
4 function TcxCustomGridTableController.FindNextItem(AFocusedItemIndex: Integer;
5 AGoForward, AGoOnCycle, AFollowVisualOrder: Boolean; out ACycleChanged: Boolean;
6 ARecord: TcxCustomGridRecord): Integer;
7 begin
8 if not FindNextCustomItem(AFocusedItemIndex, GridView.VisibleItemCount,
9 AGoForward, AGoOnCycle,
10 //modify by mofen
11 @cxCustomGridTableControllerCanTabStopItem,
12 //@cxCustomGridTableControllerCanFocusItem,
13 ARecord, Result, ACycleChanged) then
14 Result := -1;
15 end;
16
17
18
19 //此處沒有修改
20
21 function cxCustomGridTableControllerCanFocusItem(AOwner: TcxCustomGridTableView;
22 AItemIndex: Integer; AData: TObject): Boolean;
23 begin
24 Result := AOwner.VisibleItems[AItemIndex].CanFocus(TcxCustomGridRecord(AData));
25 end;
26
27
28
29 //add mofen
30 function cxCustomGridTableControllerCanTabStopItem(AOwner: TcxCustomGridTableView;
31 AItemIndex: Integer; AData: TObject): Boolean;
32 begin
33 Result := AOwner.VisibleItems[AItemIndex].CanTabStop(TcxCustomGridRecord(AData));
34 end;
35
36
37
38 //此處沒有修改
39 function TcxCustomGridTableItem.CanSort: Boolean;
40 begin
41 Result := (esoSorting in GetProperties.GetSupportedOperations) and
42 GridView.OptionsCustomize.ItemSorting and Options.Sorting;
43 end;
44
45
46
47 //add mofen
48 function TcxCustomGridTableItem.CanTabStop(
49 ARecord: TcxCustomGridRecord): Boolean;
50 begin
51 Result := CanFocus(ARecord) and FOptions.CanTabStop;
52 end;
53
54
55
56 //TcxCustomGridTableItemOptions calss
57 property Focusing: Boolean read FFocusing write SetFocusing default True;
58 //add by mofen
59 property CanTabStop: Boolean read FCanTabStop write FCanTabStop default True;
60
61
62
63 constructor TcxCustomGridTableItemOptions.Create(AItem: TcxCustomGridTableItem);
64 begin
65 inherited;
66
67 .......
68 FFilteringPopupMultiSelect := True;
69 //mofen
70 FCanTabStop := true;
71
72