Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling cell editing in TStringGrid 1

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
GB
hi

How can I restrict which cells a user can edit in a StringGrid?

I was trying this but it puts values in even if the conditions are true, think I'm on the wrong lines...

procedure TFormMain.gridColumnsSetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
begin
if ARow = 0 then exit;
if ACol <= 2 then exit;
gridColumns.Cells[ACol, ARow] := Value;
end;

Thanks for any help
lou
 
Put this in the grid's DrawCell event handler:
Code:
if (ACol > 2) and (ARow > 0) and (saveButton.Enabled) then
begin
	orderGrid.Canvas.Font.Style := [fsBold];
       	TStringGrid(Sender).Canvas.TextRect(Rect, Rect.Left, Rect.Top, TStringGrid(Sender).Cells[ACol, ARow]);

	//draw focus
        if gdFocused in State then
        	TStringGrid(Sender).Canvas.DrawFocusRect(Rect);
end;
And set goEditing to False.
 
hi MikeEd

When I type in the 'editable' cells, nothing is being displayed, have I missed something ? (the if condition is right and it goes inside it when it should).

I've set goEditing to false and put the code in the OnDrawCell.

I've noticed that the Cells[acol,arow] value is always '' when it tries to draw it in the TextRect method.

thanks for your help
lou
 
Er, sorry ignore what I posted before. I just copied some code I'd used which actually has no relevance to what you want to do.

Actually all you want to do is put the following in your SelectCell handler, which just sets goEdit appropriately depending on which cell you're in:
Code:
        if ACol > 2 then
                orderGrid.Options := orderGrid.Options + [goEditing]
        else
                orderGrid.Options := orderGrid.Options - [goEditing];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top