Skip to content

Commit 36c2ec1

Browse files
committed
Added a new combobox to select what happens when pressing the ENTER (RETURN) key while NOT editing cells in the grid. Also made more robust
1 parent 2951082 commit 36c2ec1

5 files changed

Lines changed: 102 additions & 30 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ src/
4646

4747
demos/FireMonkey/TeeGridFeatures/Win32/
4848
*.rsm
49+
demos/VirtualData/Custom Sorting/__recovery/

demos/FireMonkey/Cell Editors/Unit_Editors.fmx

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ object FormCellEditors: TFormCellEditors
22
Left = 0
33
Top = 0
44
Caption = 'TeeGrid - Custom Cell Editor Controls'
5-
ClientHeight = 430
5+
ClientHeight = 483
66
ClientWidth = 640
77
FormFactor.Width = 320
88
FormFactor.Height = 480
@@ -11,12 +11,11 @@ object FormCellEditors: TFormCellEditors
1111
DesignerMasterStyle = 0
1212
object TeeGrid1: TTeeGrid
1313
Columns = <>
14-
ReadOnly = False
1514
OnCellEditing = TeeGrid1CellEditing
1615
OnCellEdited = TeeGrid1CellEdited
1716
Align = Client
1817
Size.Width = 640.000000000000000000
19-
Size.Height = 241.000000000000000000
18+
Size.Height = 262.000000000000000000
2019
Size.PlatformDefault = False
2120
TabOrder = 0
2221
_Headers = (
@@ -54,9 +53,9 @@ object FormCellEditors: TFormCellEditors
5453
end
5554
object Layout2: TLayout
5655
Align = Bottom
57-
Position.Y = 291.000000000000000000
56+
Position.Y = 312.000000000000000000
5857
Size.Width = 640.000000000000000000
59-
Size.Height = 139.000000000000000000
58+
Size.Height = 171.000000000000000000
6059
Size.PlatformDefault = False
6160
TabOrder = 2
6261
object Text2: TText
@@ -126,12 +125,12 @@ object FormCellEditors: TFormCellEditors
126125
TextSettings.HorzAlign = Leading
127126
end
128127
object Label1: TLabel
129-
Position.X = 48.000000000000000000
128+
Position.X = 22.000000000000000000
130129
Position.Y = 107.000000000000000000
131-
Size.Width = 89.000000000000000000
130+
Size.Width = 115.000000000000000000
132131
Size.Height = 17.000000000000000000
133132
Size.PlatformDefault = False
134-
Text = 'Enter Key:'
133+
Text = 'Editing Enter Key:'
135134
end
136135
object CBEnterKey: TComboBox
137136
Items.Strings = (
@@ -141,11 +140,34 @@ object FormCellEditors: TFormCellEditors
141140
ItemIndex = 0
142141
Position.X = 144.000000000000000000
143142
Position.Y = 104.000000000000000000
144-
Size.Width = 193.000000000000000000
143+
Size.Width = 249.000000000000000000
145144
Size.Height = 22.000000000000000000
146145
Size.PlatformDefault = False
147-
TabOrder = 8
146+
TabOrder = 9
148147
OnChange = CBEnterKeyChange
149148
end
149+
object Label2: TLabel
150+
Position.X = 22.000000000000000000
151+
Position.Y = 139.000000000000000000
152+
Size.Width = 114.000000000000000000
153+
Size.Height = 17.000000000000000000
154+
Size.PlatformDefault = False
155+
Text = 'Selecting Enter Key:'
156+
TabOrder = 10
157+
end
158+
object CBSelectingEnterKey: TComboBox
159+
Items.Strings = (
160+
'Move to next cell (at right and below)'
161+
'Move to cell below'
162+
'Move to next cell (at right only)')
163+
ItemIndex = 0
164+
Position.X = 144.000000000000000000
165+
Position.Y = 134.000000000000000000
166+
Size.Width = 249.000000000000000000
167+
Size.Height = 22.000000000000000000
168+
Size.PlatformDefault = False
169+
TabOrder = 8
170+
OnChange = CBSelectingEnterKeyChange
171+
end
150172
end
151173
end

demos/FireMonkey/Cell Editors/Unit_Editors.pas

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ TFormCellEditors = class(TForm)
2727
Text5: TText;
2828
Label1: TLabel;
2929
CBEnterKey: TComboBox;
30+
Label2: TLabel;
31+
CBSelectingEnterKey: TComboBox;
3032
procedure FormCreate(Sender: TObject);
3133
procedure CBCustomEditorsChange(Sender: TObject);
3234
procedure CBAutoEditChange(Sender: TObject);
@@ -38,6 +40,7 @@ TFormCellEditors = class(TForm)
3840
procedure TeeGrid1CellEdited(const Sender: TObject; const AEditor: TControl;
3941
const AColumn: TColumn; const ARow: Integer; var ChangeData: Boolean;
4042
var NewData: string);
43+
procedure CBSelectingEnterKeyChange(Sender: TObject);
4144
private
4245
{ Private declarations }
4346

@@ -56,7 +59,7 @@ implementation
5659
uses
5760
Unit_Example_Data, Unit_Utils,
5861

59-
Tee.Grid;
62+
Tee.Grid, Tee.Grid.Selection;
6063

6164
procedure TFormCellEditors.CBAlwaysVisibleChange(Sender: TObject);
6265
begin
@@ -92,6 +95,11 @@ procedure TFormCellEditors.CBSelectedTextChange(Sender: TObject);
9295
TeeGrid1.Editing.Text.Selected:=CBSelectedText.IsChecked;
9396
end;
9497

98+
procedure TFormCellEditors.CBSelectingEnterKeyChange(Sender: TObject);
99+
begin
100+
TeeGrid1.Selected.EnterKey:=TSelectingEnter(CBSelectingEnterKey.ItemIndex);
101+
end;
102+
95103
procedure TFormCellEditors.FormCreate(Sender: TObject);
96104
begin
97105
// Use random sample data
@@ -127,12 +135,18 @@ procedure TFormCellEditors.SetupCustomEditors;
127135
procedure TFormCellEditors.TeeGrid1CellEdited(const Sender: TObject;
128136
const AEditor: TControl; const AColumn: TColumn; const ARow: Integer;
129137
var ChangeData: Boolean; var NewData: string);
138+
var tmp : String;
130139
begin
131140
if AColumn=TeeGrid1.Columns['Height'] then
132141
begin
133-
ChangeData:=False;
142+
if AEditor is TTrackBar then
143+
begin
144+
ChangeData:=False;
134145

135-
TeeGrid1.Data.SetValue(AColumn,ARow,FloatToStr(TTrackBar(AEditor).Value*0.01));
146+
tmp:=FloatToStr(TTrackBar(AEditor).Value*0.01);
147+
148+
TeeGrid1.Data.SetValue(AColumn,ARow,tmp);
149+
end;
136150
end;
137151
end;
138152

@@ -153,17 +167,17 @@ procedure TFormCellEditors.TeeGrid1CellEditing(const Sender: TObject;
153167
tmpValue);
154168
end
155169
else
156-
if AColumn=TeeGrid1.Columns['EyeColor'] then
170+
if (AColumn=TeeGrid1.Columns['EyeColor']) and (AEditor is TComboColorBox) then
157171
TComboColorBox(AEditor).Color:=Round(TeeGrid1.Data.AsFloat(AColumn,ARow))
158172
else
159-
if AColumn=TeeGrid1.Columns['Height'] then
173+
if (AColumn=TeeGrid1.Columns['Height']) and (AEditor is TTrackBar) then
160174
begin
161175
TTrackBar(AEditor).Min:=400;
162176
TTrackBar(AEditor).Max:=700;
163177
TTrackBar(AEditor).Value:=100*TeeGrid1.Data.AsFloat(AColumn,ARow);
164178
end
165179
else
166-
if AColumn=TeeGrid1.Columns['Happiness'] then
180+
if (AColumn=TeeGrid1.Columns['Happiness']) and (AEditor is TNumberBox) then
167181
begin
168182
TNumberBox(AEditor).ValueType:=TNumValueType.Float;
169183
TNumberBox(AEditor).Min:=0;

demos/VCL/Cell Editors/Unit_Editors.dfm

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ object FormCellEditors: TFormCellEditors
22
Left = 0
33
Top = 0
44
Caption = 'TeeGrid - Cell Editors Example'
5-
ClientHeight = 362
5+
ClientHeight = 396
66
ClientWidth = 726
77
Color = clBtnFace
88
Font.Charset = DEFAULT_CHARSET
@@ -17,7 +17,7 @@ object FormCellEditors: TFormCellEditors
1717
Left = 0
1818
Top = 41
1919
Width = 726
20-
Height = 191
20+
Height = 183
2121
Columns = <>
2222
OnCellEditing = TeeGrid1CellEditing
2323
OnCellEdited = TeeGrid1CellEdited
@@ -61,9 +61,9 @@ object FormCellEditors: TFormCellEditors
6161
end
6262
object Panel2: TPanel
6363
Left = 0
64-
Top = 232
64+
Top = 224
6565
Width = 726
66-
Height = 130
66+
Height = 172
6767
Align = alBottom
6868
TabOrder = 2
6969
object Label2: TLabel
@@ -92,11 +92,11 @@ object FormCellEditors: TFormCellEditors
9292
' to another cells'
9393
end
9494
object Label5: TLabel
95-
Left = 71
95+
Left = 36
9696
Top = 102
97-
Width = 50
97+
Width = 85
9898
Height = 13
99-
Caption = 'Enter key:'
99+
Caption = 'Editing Enter key:'
100100
end
101101
object Label6: TLabel
102102
Left = 127
@@ -107,6 +107,13 @@ object FormCellEditors: TFormCellEditors
107107
'True = Cell editor using TEdit will select all text when showing' +
108108
' it'
109109
end
110+
object Label7: TLabel
111+
Left = 25
112+
Top = 129
113+
Width = 96
114+
Height = 13
115+
Caption = 'Selecting Enter key:'
116+
end
110117
object CBAutoEdit: TCheckBox
111118
Left = 24
112119
Top = 25
@@ -128,7 +135,7 @@ object FormCellEditors: TFormCellEditors
128135
object CBEnterKey: TComboBox
129136
Left = 127
130137
Top = 99
131-
Width = 194
138+
Width = 242
132139
Height = 21
133140
Style = csDropDownList
134141
ItemIndex = 0
@@ -176,5 +183,20 @@ object FormCellEditors: TFormCellEditors
176183
TabOrder = 6
177184
OnClick = Button3Click
178185
end
186+
object CBSelectingEnter: TComboBox
187+
Left = 127
188+
Top = 126
189+
Width = 242
190+
Height = 21
191+
Style = csDropDownList
192+
ItemIndex = 0
193+
TabOrder = 7
194+
Text = 'Move to next cell at right and bottom'
195+
OnChange = CBSelectingEnterChange
196+
Items.Strings = (
197+
'Move to next cell at right and bottom'
198+
'Move to cell below'
199+
'Move to next cell at right')
200+
end
179201
end
180202
end

demos/VCL/Cell Editors/Unit_Editors.pas

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ TFormCellEditors = class(TForm)
5353
Button1: TButton;
5454
Button2: TButton;
5555
Button3: TButton;
56+
Label7: TLabel;
57+
CBSelectingEnter: TComboBox;
5658
procedure FormCreate(Sender: TObject);
5759
procedure CBAutoEditClick(Sender: TObject);
5860
procedure CBAlwaysVisibleClick(Sender: TObject);
@@ -67,6 +69,7 @@ TFormCellEditors = class(TForm)
6769
procedure Button1Click(Sender: TObject);
6870
procedure Button2Click(Sender: TObject);
6971
procedure Button3Click(Sender: TObject);
72+
procedure CBSelectingEnterChange(Sender: TObject);
7073
private
7174
{ Private declarations }
7275

@@ -87,7 +90,7 @@ implementation
8790

8891
VCLTee.Painter,
8992

90-
Tee.Grid, System.UITypes, Tee.Grid.Rows, Tee.Format;
93+
Tee.Grid, System.UITypes, Tee.Grid.Rows, Tee.Format, Tee.Grid.Selection;
9194

9295
procedure TFormCellEditors.Button1Click(Sender: TObject);
9396
var cell : TCell;
@@ -166,6 +169,12 @@ procedure TFormCellEditors.CBSelectedTextClick(Sender: TObject);
166169
TeeGrid1.Editing.Text.Selected:=CBSelectedText.Checked;
167170
end;
168171

172+
procedure TFormCellEditors.CBSelectingEnterChange(Sender: TObject);
173+
begin
174+
// Several options when pressing the Enter key while NOT editing a cell (selecting cells only)
175+
TeeGrid1.Selected.EnterKey:=TSelectingEnter(CBSelectingEnter.ItemIndex);
176+
end;
177+
169178
procedure TFormCellEditors.FormCreate(Sender: TObject);
170179
begin
171180
// Example, switch from Windows GDI+ graphics to GDI:
@@ -215,12 +224,15 @@ procedure TFormCellEditors.TeeGrid1CellEdited(const Sender: TObject;
215224
// Example, retrieve position from TrackBar
216225
if AColumn=TeeGrid1.Columns['Height'] then
217226
begin
218-
tmp:=0.01*TTrackBar(AEditor).Position;
227+
if AEditor is TTrackBar then
228+
begin
229+
tmp:=0.01*TTrackBar(AEditor).Position;
219230

220-
TeeGrid1.Data.SetValue(AColumn,ARow,FloatToStr(tmp));
231+
TeeGrid1.Data.SetValue(AColumn,ARow,FloatToStr(tmp));
221232

222-
// Set to False, do not change grid cell data
223-
ChangeData:=False;
233+
// Set to False, do not change grid cell data
234+
ChangeData:=False;
235+
end;
224236
end
225237
else
226238
if AEditor is TComboBox then
@@ -287,7 +299,8 @@ procedure TFormCellEditors.TeeGrid1CellEditing(const Sender: TObject;
287299

288300
// Example, use a trackbar as cell editor
289301
if AColumn=TeeGrid1.Columns['Height'] then
290-
SetupTrackBar(TTrackBar(AEditor));
302+
if AEditor is TTrackBar then
303+
SetupTrackBar(TTrackBar(AEditor));
291304
end;
292305

293306
{ TComboBox }

0 commit comments

Comments
 (0)