Recent

Author Topic: plus methods to tstringgrid  (Read 6206 times)

rodrigo

  • Guest
plus methods to tstringgrid
« on: October 25, 2005, 03:14:12 pm »
its methods will help more:

hidecol(const index:integer); {hide column of grid}
hiderow(const index:integer); {hide row of grid}
sortbycolumn(const column:integer;const typeofdata; const ascend/desc);{sort by column}

jesusr

  • Sr. Member
  • ****
  • Posts: 484
RE: plus methods to tstringgrid
« Reply #1 on: October 25, 2005, 10:18:14 pm »
requested functionality can be done with following  changes:

Code: [Select]

  //to hide columns
  //grid.HideCol(3);
  grid.ColWidths[3] := 0;

  //to hide rows
  //grid.HideRow(3);
  grid.RowHeights[3]:=0;


for SortByColumn(?, ?, ?) write an OnCompareCells for grid and in handler write something like:
Code: [Select]

....
begin
  result := FunctionToCompareTwoStrings(grid.Cells[aCol,aRow], grid.Cells[bCol,bRow])
 // the function should return  <0 if CellA<CellB >0 if CellA>CellB
 // and 0 if CellA=CellB
 // for example to simply compare strings use:
 // result := CompareText(grid.Cells[aCol,aRow], grid.Cells[bCol,bRow]);
 // this will sort ascending, to sort descending simply invert compare
 // expresion or multiply by -1 the result
end;


then you can replace

Code: [Select]

  //SortByColumn(3, ?, ?);
  grid.SortColRow(True {so is a column}, 3);


Maybe it could be useful to write SortColRow(bool, index, param) so OnCompareCells include a param which could be used for example to
select descending or ascending or any other purpose, in this case
  grid.SortColRow(True, 3, Integer(true)); for ascending
  grid.SortColRow(True, 3, Integer(false)); for descending and OnCompareCells: if Boolean(Param) then .... else .....;

if you feel like it could be useful fill a "request feature" report in bug tracker

 

TinyPortal © 2005-2018