Recent

Author Topic: [SOLVED] DBGRID | Picklist on field  (Read 581 times)

bourbon

  • Newbie
  • Posts: 5
[SOLVED] DBGRID | Picklist on field
« on: September 16, 2024, 05:58:04 pm »
Hello,
I am using a program that I developed under Linux. I want to be able to use it under Windows. The compilation is done well, but in use, it is impossible to modify the presentation (display width) of a drop-down list in a grid.

Linux mint 22
Windows 7
Lazarus v3.4

I have the same problem with Lazarus v2.2

Thanks

Edit
This is what I want to achieve
« Last Edit: September 19, 2024, 08:50:45 pm by bourbon »

korba812

  • Sr. Member
  • ****
  • Posts: 417
Re: DBGRID | Picklist on field
« Reply #1 on: September 16, 2024, 11:52:34 pm »
You can use OnSelectEditor event and customize editor control.

Code: Pascal  [Select][+][-]
  1. type
  2.   TFakeEditor = class(TPickListCellEditor)
  3.  
  4.   end;
  5.  
  6. procedure TForm1.DBGrid1SelectEditor(Sender: TObject; Column: TColumn;
  7.   var Editor: TWinControl);
  8. begin
  9.   if {(Column = MyColumn) and} (Editor is TPickListCellEditor) then
  10.     TFakeEditor(Editor).ItemWidth := 160;
  11. end;
  12.  
Unfortunately ItemWidth property is protected in TPickListCellEditor so in example I used a workaround (subclassing).

bourbon

  • Newbie
  • Posts: 5
Re: DBGRID | Picklist on field
« Reply #2 on: September 18, 2024, 08:10:01 pm »
Thank you korba812. Before I start with this solution, I would like to understand what is happening.

Indeed, I do not understand why it works perfectly when compiling under Linux, and not when compiling under Windows.
I duplicated the complete Linux folder in a folder that I use to compile my program under Windows so as not to mix the sources.
The Windows compilation goes well, everything works, except this picklist in the grid.

When I click on the button, the list is displayed, but is absolutely not usable, given its very small width (it is almost unreadable)

I compared all the attributes, line by line, of the following components:
1- the dbgrid
2- the field that poses a problem in the grid
3- the same field in my table

Everything is similar (except the operation...)

TRon

  • Hero Member
  • *****
  • Posts: 3255
Re: DBGRID | Picklist on field
« Reply #3 on: September 18, 2024, 08:27:42 pm »
Thank you korba812. Before I start with this solution, I would like to understand what is happening.
I am not familiar with this particular case (not using windows) but realize that sometimes it is a limitation of the used widgetset. Whether or not it can be solved, I do not know.

It is the reason why there exist f.e. custom drawn controls (that usually acts/behaves the same on/for different platforms/widgetsets).

Therefor it might be as simple as it is just the way it is (and in which case korba's suggested solution might be the only way to solve it).
All software is open source (as long as you can read assembler)

bourbon

  • Newbie
  • Posts: 5
Re: DBGRID | Picklist on field
« Reply #4 on: September 18, 2024, 10:08:42 pm »
OK, but why does it work under Linux, and the same program (same sources) does not work with a compilation under Windows?

Lazarus' argument is precisely that everything compiles under different systems, without rewriting anything?

Is there a use declaration or something missing? A bug, perhaps?
I find it hard to believe that this behavior could be different, depending on the OS. A modify in the compiler could not have been made voluntarily?

Precision:
The first image is the result under windows (bad)
The last image is the result under linux (good)
« Last Edit: September 18, 2024, 10:12:31 pm by bourbon »

TRon

  • Hero Member
  • *****
  • Posts: 3255
Re: DBGRID | Picklist on field
« Reply #5 on: September 18, 2024, 10:25:50 pm »
OK, but why does it work under Linux, and the same program (same sources) does not work with a compilation under Windows?

Lazarus' argument is precisely that everything compiles under different systems, without rewriting anything?
Oh, it compiles but that does not say anything about differences in widgetset behaviour.

Quote
Is there a use declaration or something missing? A bug, perhaps?
For this particular case, I do not know. If korba's solution works then it seems like an oversight which could perhaps be addressed. In that regards I agree that the behaviour can be the same once implemented correctly.

Quote
I find it hard to believe that this behavior could be different, depending on the OS. A modify in the compiler could not have been made voluntarily?
I hate to burst the bubble but f.i. also see Lazarus known issues (things that will never be fixed)

It is in the nature of how the LCL works and is implemented. There are other solutions such as fpGui and MSE that more or less guarantee to have the same (visual) behaviour for the different targets.

And as mentioned earlier custom drawn controls tries to solve such issues as well.

Keep in mind that LCL is basically legacy because of Delphi (compatibility), no matter what personal opinion we might have about that. As a result things might not work the same because it is impossible to implement the same behaviour. See also roadmap.
« Last Edit: September 18, 2024, 10:28:46 pm by TRon »
All software is open source (as long as you can read assembler)

bourbon

  • Newbie
  • Posts: 5
Re: DBGRID | Picklist on field
« Reply #6 on: September 19, 2024, 02:54:05 pm »
I implemented the example given by korba812. It works perfectly. But I would allike to be able to modify the font displayed in this picklist.
I tried this instruction (I would like a fixed-width font):
Code: Pascal  [Select][+][-]
  1. TFakeEditor(Editor).Font.Name := 'Courrier New';

It does not crash, but nothing changes. Any leads?

rvk

  • Hero Member
  • *****
  • Posts: 6362
Re: DBGRID | Picklist on field
« Reply #7 on: September 19, 2024, 03:14:44 pm »
I implemented the example given by korba812. It works perfectly. But I would allike to be able to modify the font displayed in this picklist.
I tried this instruction (I would like a fixed-width font):
Code: Pascal  [Select][+][-]
  1. TFakeEditor(Editor).Font.Name := 'Courrier New';

It does not crash, but nothing changes. Any leads?
It does work if you don't make any typos  :P

It's Courier New, not Courrier New  ;)

bourbon

  • Newbie
  • Posts: 5
Re: DBGRID | Picklist on field
« Reply #8 on: September 19, 2024, 08:49:29 pm »
Quote
It's Courier New, not Courrier New  ;)

Oh yes, indeed, it is much better  :D. Thank you and congratulations for your keen eye (at my place, mail, courrier en Français,  is written with 2 "r", so that had not caught my attention)

 

TinyPortal © 2005-2018