And:
procedure TForm1.FormShow(Sender: TObject);
begin
Edit6.SetFocus;
Edit6.SelectAll;
end;
Main Topics
Browse All TopicsI am making a tool looks like http://www.geocities.jp/mi
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
A simple solution would be just to play around with the stringrid properties - like this
object Form1: TForm1
Left = 192
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object StringGrid1: TStringGrid
Left = 192
Top = 64
Width = 201
Height = 81
BorderStyle = bsNone
Color = clBtnFace
ColCount = 3
FixedCols = 0
RowCount = 3
FixedRows = 0
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Bell MT'
Font.Style = [fsBold]
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing]
ParentFont = False
ScrollBars = ssNone
TabOrder = 0
OnSelectCell = StringGrid1SelectCell
end
end
& the code to avoid people editing the row/col headers:
procedure TForm1.StringGrid1SelectCe
ARow: Integer; var CanSelect: Boolean);
begin
If (Arow=0) or (ACol=0) then CanSelect:= false;
end;
David
aikimark > true lol
mikezang > the code works for me, I am guessing that we aren't prehaphs using the same properties for the stringgrid - download this example
www.davidbirch2.com/hidden
David
in your FormCreate do this
var
myRect: TGridRect;
begin
stringgrid1.cells[2, 2] := '3'; // add some data to the grid
{ optional
myRect.Left := 2; // set which cell is selected
myRect.Top := 2; // set which cell is selected
myRect.Right := 2; // set which cell is selected
myRect.Bottom := 2; // set which cell is selected
StringGrid1.Selection := myRect; // set which cell is selected
}
StringGrid1.Col:= 2; // set the selected cell as well
StringGrid1.row:= 2; // set the selected cell as well
StringGrid1.Options := StringGrid1.Options + [goEditing]; // allow editing
end;
and then in the SelectCell event do this :-
procedure TForm1.StringGrid1SelectCe
begin
if (StringGrid1.Cells[ACol,AR
begin
StringGrid1.Options := StringGrid1.Options + [goEditing]; //allow editing if cell has data
CanSelect := True; //allow selection if cell has data
end
else
begin
StringGrid1.Options := StringGrid1.Options - [goEditing]; //disallow editing if cell is empty
CanSelect := False; //do not allow selection if cell is empty
end
end;
Hi, TheRealLoki
I did the same as your code, but it doesn't work, I have a source, can you check it for me?
http://www.geocities.jp/mi
you do need the
grd.Options := grd.Options + [goEditing];
line, which you had commented out, to enable editing again if the user clicks in that area.
you might also like to add an "onEnter" event that fouses that cell and enables the editing (so you can tab into it and make changes instead of needing the mouse)
procedure TForm1.StringGrid1Enter(Se
begin
(sender as TStringGrid).col := 2;
(sender as TStringGrid).row := 2;
(sender as TStringGrid).Options := (sender as TStringGrid).Options + [goEditing]; //allow editing if cell has data
(sender as TStringGrid).EditorMode := True; // so the 1st character you type is written
end;
Try just this, it is a lot simpler, but I think it does everything you need
procedure TForm1.StringGrid1SelectCe
begin
CanSelect := ( (ACol = 2) and (ARow = 2) );
end;
and set your StringGrid.Options to have
goDrawFocusSelected, goEditing, goAlwaysShowEditor set to true
erm I was just looking at your source - on the first table on the onselectcell event you had
if (ACol = 1) and (ARow = 1) then
begin
// grd.Options := grd.Options + [goEditing];
CanSelect := false;
end
else
begin
grd.Options := grd.Options - [goEditing];
CanSelect := false;
end
if both options are false then you will never be able to select the cell !?
try changing it to
if (ACol = 1) and (ARow = 1) then
begin
grd.Options := grd.Options + [goEditing];
CanSelect := true;
end
else
begin
grd.Options := grd.Options - [goEditing];
CanSelect := false;
end
Which works for me
David
Hi, David
That source is old, I used that to try something, but I didn't get what I need, I have to click on that cell to get focus.
Or The focus will be set to cells[0, 0], even I set to cells[1,1] or col=1 and row=1.
You can try again and tell me the result. Can you use TAB to get focus on cells[1, 1]?
mikezang > I am on a machine which is delphi-less :( but can you check if the string grid has a ongetfocus event ? if so put something like this on it:
(sender as TStringGrid).col := 2;
(sender as TStringGrid).row := 2;
(sender as TStringGrid).Options := (sender as TStringGrid).Options + [goEditing]; //allow editing if cell has data
(sender as TStringGrid).EditorMode := True; // so the 1st character you type is written
David
Can you show me a simplest full sample? My screen looks like http://www.geocities.jp/mi
Business Accounts
Answer for Membership
by: calinutzPosted on 2005-03-26 at 12:39:14ID: 13637129
Why does it have to be a Grid? Why not use Edits like this here:
object Form1: TForm1
Left = 192
Top = 107
Width = 260
Height = 640
Caption = 'Form1'
Color = 14408667
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object GroupBox1: TGroupBox
Left = 3
Top = 254
Width = 247
Height = 95
Caption = 'Commerce per turn'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 0
object Edit1: TEdit
Left = 2
Top = 13
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = 729840
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 0
Text = '0%'
end
object Edit2: TEdit
Left = 2
Top = 33
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 1
Text = 'Produce'
end
object Edit3: TEdit
Left = 2
Top = 53
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = 729840
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 2
Text = 'Corruption'
end
object Edit4: TEdit
Left = 2
Top = 73
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 3
Text = 'Rest'
end
object Edit5: TEdit
Left = 83
Top = 13
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 4
Text = 'Curent'
end
object Edit6: TEdit
Left = 83
Top = 33
Width = 80
Height = 19
BorderStyle = bsNone
Color = clWhite
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 5
Text = '3'
end
object Edit7: TEdit
Left = 83
Top = 53
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 6
end
object Edit8: TEdit
Left = 83
Top = 73
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 7
end
object Edit9: TEdit
Left = 164
Top = 13
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 8
Text = 'Estimate'
end
object Edit10: TEdit
Left = 164
Top = 33
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 9
Text = '3'
end
object Edit11: TEdit
Left = 164
Top = 53
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 10
end
object Edit12: TEdit
Left = 164
Top = 73
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 11
end
end
object GroupBox2: TGroupBox
Left = 3
Top = 158
Width = 247
Height = 95
Caption = 'Shields per turn'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 1
object Edit13: TEdit
Left = 2
Top = 13
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = 729840
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 0
Text = '0%'
end
object Edit14: TEdit
Left = 2
Top = 33
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 1
Text = 'Produce'
end
object Edit15: TEdit
Left = 2
Top = 53
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = 223
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 2
Text = 'Corruption'
end
object Edit16: TEdit
Left = 2
Top = 73
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 3
Text = 'Rest'
end
object Edit17: TEdit
Left = 83
Top = 13
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 4
Text = 'Curent'
end
object Edit18: TEdit
Left = 83
Top = 33
Width = 80
Height = 19
BorderStyle = bsNone
Color = clWhite
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 5
Text = '3'
end
object Edit19: TEdit
Left = 83
Top = 53
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 6
end
object Edit20: TEdit
Left = 83
Top = 73
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 7
end
object Edit21: TEdit
Left = 164
Top = 13
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 8
Text = 'Estimate'
end
object Edit22: TEdit
Left = 164
Top = 33
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 9
Text = '3'
end
object Edit23: TEdit
Left = 164
Top = 53
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 10
end
object Edit24: TEdit
Left = 164
Top = 73
Width = 80
Height = 19
BorderStyle = bsNone
Color = clSilver
Ctl3D = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentCtl3D = False
ParentFont = False
TabOrder = 11
end
end
end