Lazarus

Programming => General => Topic started by: SteveSS on February 14, 2018, 06:38:52 pm

Title: TDbgrid Question [SOLVED]
Post by: SteveSS 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
Title: Re: TDbgrid Question
Post by: valdir.marcos 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.
Title: Re: TDbgrid Question
Post by: Swirl 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
Title: Re: TDbgrid Question
Post by: SteveSS 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
Title: Re: TDbgrid Question
Post by: madref 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  
Title: Re: TDbgrid Question
Post by: SteveSS 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
Title: Re: TDbgrid Question [SOLVED]
Post by: Swirl 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
TinyPortal © 2005-2018