Posted by Deepthy on December 01, 2006
I gave coding to edit directly into the stringgrid and a word wrap coding also (Please see the below coding). But at a time both will not work. If i want to edit directly into the cells of stringgrid the word wrap will not work, if i remove the coding of goediting then the word wrap will work find. Do anybody have a solution for this. I want to edit directly into the stringgrid cell without using and edit control and the word wrap should also happen, what can i do for this? If anybody can help please help me......For word wrap in the string grid. In this case i have to use an edit box to edit the cell of the stringgrid
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
P : array[0..255] of Char;
RTRowHeight : integer;
begin
{ Here checks for the row and column and setting row width }
if (ARow >= 1) and (ACol = 2) then
begin
StringGrid1.Canvas.FillRect(Rect);
StrPCopy(P, StringGrid1.Cells[2, ARow]);
{ Here happens the word wrap }
RTRowHeight := DrawText(StringGrid1.Canvas.Handle, P, -1, Rect, DT_WORDBREAK);
{ Here it adjust the rowheight according to the requirement. }
if RTRowHeight > StringGrid1.RowHeights[ARow] then
begin
StringGrid1.RowHeights[ARow]:= RTRowHeight + 2;
end;
end;
end;
In order to edit directly into a particular cell of the stringgrid
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
if ((ACol = 2) and (ARow = 1)) then
begin
StringGrid1.Options := StringGrid1.Options + [goEditing];
end
else
begin
StringGrid1.Options := StringGrid1.Options - [goEditing];
end;
end;
Thanks,
Deepthy
Related articles
| Stringgrid vs ValueListEditor If you don't have a ValueListEditor component, you can simulate it with a StringGrid |
Follow Ups
Post a Followup
DelphiLand Club members: enter your Membership password.
Guests can get a Forum Guest password by subscribing to the DelphiLand Newsletter.