一个软件的成功除了跟软件的灵活性和功能有很大关系之外,其实操作的便利性也占了很大一部分,特别是想抢占其他软件的领域的时候。实施的成功与否跟操作者有着很大的关系,要直接用户的认可,在数据的输入方面就要花费很大的功夫了。
公司的项目都是用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
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