Recent

Author Topic: String Grid  (Read 3870 times)

Rodney

  • New Member
  • *
  • Posts: 11
String Grid
« on: February 16, 2013, 01:14:28 pm »
Hopefully this is a very simple question...

I am displaying a % value in all of the columns of the Row 2 of my grid and so I want the format of the cells in that row to be <99.9 and displaying to 1 decimal place.
I have used the OnGetEditMask event and my code is:

    if ARow = 2 Then
       Value:='99.9';

Everything compiles but all the values are still displaying to 7 decimal places!

Is there something else that I should be doing?

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: String Grid
« Reply #1 on: February 16, 2013, 01:27:16 pm »
It has nothing to do with OnGetEditMask. StringGrid contains strings.
I assune you have some routine where you fill the grid with data. You can do:
Code: [Select]
var f: Double;
...
if f>99.9 then f:=99.9;
Cells[2, y]:=FloatToStrF[f, ffFixed, 0, 1];

If user inserts data directly to cell (i.e. grid is not read-only), you can use any cell editor (TFloatSpinEdit should be fine). Or use OnEditingDone to correct inserted value immediately after editing.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Rodney

  • New Member
  • *
  • Posts: 11
Re: String Grid
« Reply #2 on: February 16, 2013, 02:12:15 pm »
Thanks very much Blaazen - that works fine.  What is OnGetEditMask used for?

Bart

  • Hero Member
  • *****
  • Posts: 5649
    • Bart en Mariska's Webstek
Re: String Grid
« Reply #3 on: February 16, 2013, 02:25:24 pm »
Can't you set an EditMask in OnGetEditor?
(Too lazy to test myself obviously).

Bart

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: String Grid
« Reply #4 on: February 16, 2013, 03:08:27 pm »
@ It has nothing to do with OnGetEditMask.
 ;D
I was NOT right. Your original code works well in case that data are manually edited.
I tested this:
Code: [Select]
procedure TForm1.StringGrid1GetEditMask(Sender: TObject; ACol, ARow: Integer;
  var Value: string);
begin
  Value:='99'+FormatSettings.DecimalSeparator+'9';
end;     
Note that you have to add unit "clocale" to uses of *.lpr file to activate formatsettings.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018