Hi Group,
would there be a problem with StringGrid on
Lazarus 0.9.28.2 r22279 FPC 2.2.4 i386-win32-win32/win64
that is preventing MouseToCell from working correctly if
some columns have been deleted ?
(snippet)
{ put a StringGrid1 on the form }
{have one row fixed FixedRows := 1}
{hook this to the OnShow of the Form}
procedure TForm1.FormShow(Sender: TObject);
var column, line : integer;
begin
StringGrid1.RowCount := 10;
StringGrid1.ColCount := 10;
{this is just for filling the grid with demo data, the real project
was reading it from file, using 2 StringLists on the way, to
determine how many rows and cols there shall be}
for line := 0 to StringGrid1.RowCount-1 do
for column := 0 to StringGrid1.ColCount-1 do
begin
StringGrid1.Cells[column,line] := Format('Column %d',[column]);
end;
{now merge content of sequent even and odd columns
for line := 0 to StringGrid1.RowCount-1 do
for column := 0 to StringGrid1.ColCount-2 do
begin
StringGrid1.Cells[column,line] := StringGrid1.Cells[column,line] + ' '+
StringGrid1.Cells[column+1,line];
end;
{now delete the odd columns }
{result will be 'Column 0 Column1|Column 2 Column 3|Column 4 Column 5 (and so
on) }
{ does not matter if there is Begin/EndUpdate surrounding all string grid
operations }
for column := StringGrid.ColCount-1 downto 1 step 2 do
StringGrid1.DeleteColRow(true,column);
// or just plain
// StringGrid1.DeleteColRow(true, 9);
// StringGrid1.DeleteColRow(true, 7);
// StringGrid1.DeleteColRow(true, 5);
// StringGrid1.DeleteColRow(true, 3);
// StringGrid1.DeleteColRow(true, 1);
{you should end up with 5 columns on the grid}
end;
{ put this on OnClick of the stringgrid}
procedure TForm1.StringGrid1Click(Sender: TObject);
var gridcell : TPoint;
begin
gridcell := StringGrid1.MouseToCell(Mouse.CursorPos);
StringGrid1.Cells[gridcell.x,0] := IntToStr(gridcell.x);
{what text do you get in fixed row of the visible column you've just clicked
?}
{my project got 0, 2, 4, 6, 8 }
{and I want 0,1,2,3,4 actually}
end;
My project is a little more complicated than above (the above has not been
compile
tested, it is just an idea of POC), but involves reading data from file
( space separated columns where it is data-dependent how many should be merged
but
still supporting name="value" convention) ).
Would that be TStringGrid bug or my thinko ?
Thanks,
Lukasz
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus