* * *

Author Topic: TDbgrid Question [SOLVED]  (Read 1097 times)

SteveSS

  • New member
  • *
  • Posts: 24
TDbgrid Question [SOLVED]
« on: February 14, 2018, 06:38:52 pm »
Hi All.  Recently installed 1.8.  All seemed ok but I have found a strange problem that I can't seem to fix.
My application uses a TDbgrid, with two fixed columns, and has various extra columns added depending on user selections.  The first column is for a name, and the problem is that I can't seem to adjust the width of the column.  In the Lazarus editor, if I change the width of the second column you can see it change on the screen but this does not happen for the first column.  I must be missing something (again).  Any ideas?

Steve
« Last Edit: February 14, 2018, 10:27:15 pm by SteveSS »

valdir.marcos

  • Sr. Member
  • ****
  • Posts: 418
Re: TDbgrid Question
« Reply #1 on: February 14, 2018, 08:21:56 pm »
Please attach a zipped small sample project (lpr, lpi, lfm, pas, etc: all source files) via Project menu/Publish project.

Swirl

  • New member
  • *
  • Posts: 14
Re: TDbgrid Question
« Reply #2 on: February 14, 2018, 08:26:27 pm »
Hi SteveSS,
tried to reproduce your problem, but any fixed column could be resized.
Tried 4 fixed ones - all sizable. Please tell step by step the way you
assign the width of columns...
Btw - Windows, Linux, Apple? Did you try to resize during runtime?
Regards
Mike
« Last Edit: February 14, 2018, 08:29:51 pm by Swirl »
Lazarus: 1.6.4 (2017-02-27) - FPC 3.0.2 - SVN-Revision: 54278 - x86_64-win32/win64 - Windows7pro/64Bit

SteveSS

  • New member
  • *
  • Posts: 24
Re: TDbgrid Question
« Reply #3 on: February 14, 2018, 10:04:51 pm »
Hi Mike
 
Windows 10.   Not tried to change at run time - don't really want that.  The way I change the width:

1. Load Lazarus
2. Open the project
3. Open the .pas file
4. Switch to form designer mode
5. Select the grid then column 0
6. Change the width property - the column displayed on the screen does not change width but if I select column 1 and change the width, the screen display of the grid changes.

The code was written under Lazarus 1.6.4.  I am now on 1.8 so will probably try deleting the grid component and adding it back to the form in case there has been any changes in the background.

Steve

madref

  • Sr. Member
  • ****
  • Posts: 471
  • ..... A day not Laughed is a day not Lived !!
    • Nursing With Humour
Re: TDbgrid Question
« Reply #4 on: February 14, 2018, 10:23:01 pm »
This is what i do:
Code: Pascal  [Select]
  1. type
  2.   TMyDBGridHelper = class Helper for TDBGrid
  3.   public
  4.     function _ColumnByName(sFieldname: string): TColumn;
  5.   end;  // TMyDBGridHelper
  6.  
and then start adjusting what i want by:
Code: Pascal  [Select]
  1. procedure TForm_Evaluatie_Overzicht.Format_Grid_Evaluaties;
  2. begin
  3.   if not DBGrid_Evaluaties.DataSource.DataSet.Active then exit;
  4.   DBGrid_Evaluaties._ColumnByName('ID').Width := 0;
  5.   DBGrid_Evaluaties._ColumnByName('Referee').Width := 175;
  6.   DBGrid_Evaluaties._ColumnByName('Scheids_ID').Width := 0;
  7.   DBGrid_Evaluaties._ColumnByName('Division').Width := 75;
  8.   DBGrid_Evaluaties._ColumnByName('Date').Width := 90;
  9.   DBGrid_Evaluaties._ColumnByName('Time').Width := 45;
  10.   DBGrid_Evaluaties._ColumnByName('Team A').Width := 225;
  11.   DBGrid_Evaluaties._ColumnByName('Team B').Width := 225;
  12.   DBGrid_Evaluaties._ColumnByName('Seizoen').Width := 0;
  13.   DBGrid_Evaluaties._ColumnByName('Wed_ID').Width := 0;
  14.   DBGrid_Evaluaties._ColumnByName('TBL').Width := 0;
  15.   DBGrid_Evaluaties._ColumnByName('Position').Width := 67;
  16.   DBGrid_Evaluaties._ColumnByName('System').Width := 63;
  17.   DBGrid_Evaluaties._ColumnByName('DD').Width := 0;
  18. end;     // Format_Grid_Evaluaties  
You treat a disease, you win, you lose.
You treat a person and I guarantee you win, no matter the outcome.

Lazarus 1.8.4 / FPC 3.0.4
Lazarus Trunk / FPC Trunk
Mac OS X High Sierra

SteveSS

  • New member
  • *
  • Posts: 24
Re: TDbgrid Question
« Reply #5 on: February 14, 2018, 10:25:04 pm »
Hi All

Just done what I said I would try in my last post - deleted and re-added the TDbgrid component and now I can change column widths without any problem.  Guess something must have changed behind the scenes between 1.6.4 and 1.8.

Now solved.

Steve

Swirl

  • New member
  • *
  • Posts: 14
Re: TDbgrid Question [SOLVED]
« Reply #6 on: February 15, 2018, 12:52:39 pm »
Thx for the hint. By the way step 1 to 6 were/are ok.
I'll give it a try and upgrade to 1.8 (as advised some months ago) on a win10 machine.
Sometimes reinstalling or just rebooting does it.
Grats
Mike
Lazarus: 1.6.4 (2017-02-27) - FPC 3.0.2 - SVN-Revision: 54278 - x86_64-win32/win64 - Windows7pro/64Bit

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus