Recent

Author Topic: Make Combobox readonly for editing  (Read 616 times)

mangakissa

  • Hero Member
  • *****
  • Posts: 1065
Make Combobox readonly for editing
« on: April 08, 2020, 12:52:22 pm »
In Version 2.x TCombobox.readonly is depreciated. Using TCombobox.style is required.
But property style doesn't make my combobox readonly. If a form starts and it should be in edit mode (it my case it means the combobox is readonly) I can do nothing with the combobox. Even the events oncloseup are not responding.

So How do I make my combobox really readonly ?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

zeljko

  • Hero Member
  • *****
  • Posts: 1141
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Make Combobox readonly for editing
« Reply #1 on: April 08, 2020, 01:03:18 pm »
Yes, property ReadOnly is removed some time ago but I really don't know exact reason.
You'll need to hack into combo editor and set it read only manually.
eg with Qt/Qt5 widgetsets TQtComboBox(ComboBox1.Handle).LineEdit.setReadOnly(True) works fine.

mangakissa

  • Hero Member
  • *****
  • Posts: 1065
Re: Make Combobox readonly for editing
« Reply #2 on: April 08, 2020, 01:13:10 pm »
I changed te readonly to enable. Now I get the same result.

I see in my old application I forgot the compontent to set it readonly in 'edit' mode. Stupid me  :'(
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

sstvmaster

  • Full Member
  • ***
  • Posts: 157
Re: Make Combobox readonly for editing
« Reply #3 on: April 08, 2020, 01:24:48 pm »
Set:
Code: Pascal  [Select][+][-]
  1. ComboBox1.Style := csOwnerDrawFixed; // or csDropDownList or csOwnerDrawVariable
then its readonly!
Windows 10 (64 bit)
Lazarus: 2.0.8 / Trunk x32

jamie

  • Hero Member
  • *****
  • Posts: 3077
Re: Make Combobox readonly for editing
« Reply #4 on: April 08, 2020, 02:06:28 pm »
Really?

 I thought that was only to not have variable sized dropped down list box entries and Edit box..

There is a OnMeasureItem event for variable, otherwise its fixed sized...

 don't remember it effecting the editing options..

 I retract what I said, I can't believe Delphi would change that order. it makes no sense at all, so what happens if I decide to want to optionally make the combobox editable at will at runtime, have anyone changed the style at runtime to see the effects ?
« Last Edit: April 08, 2020, 02:26:31 pm by jamie »
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 7213
Re: Make Combobox readonly for editing
« Reply #5 on: April 08, 2020, 02:45:56 pm »
What is meant with "editing" here?

The possibility to type text immediately into the control, like is done with a TEdit? Here the styles csDropDownList, csOwnerDrawFixed, csOwnerDrawVariable can be selected to prevent this. And in fact, the property "ReadOnly" switches to an unchangeable "true" state in this case.

Or the possibility to change the selection? Here, I can imagine only to prevent a change by code which memorizes the ItemIndex in the OnDropDown event and restores it in the OnChange event - there is a short flicker showing the changed ItemIndex, though.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

jamie

  • Hero Member
  • *****
  • Posts: 3077
Re: Make Combobox readonly for editing
« Reply #6 on: April 08, 2020, 03:45:50 pm »
What I meant was I toggle the READ only property so not to allow editing at times where it should not be changed..

 Since Delphi now as taken the pose of removing the READ Only property has any one tested the behavior of  The Combobox switching between these modes at runtime ?
 
 Obviously now we need to change the style property to achieve this and I do make ownerdraw comboxs due to special editing and viewing options.
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 2919
Re: Make Combobox readonly for editing
« Reply #7 on: April 08, 2020, 04:11:08 pm »
I retract what I said, I can't believe Delphi would change that order. it makes no sense at all, so what happens if I decide to want to optionally make the combobox editable at will at runtime, have anyone changed the style at runtime to see the effects ?

For those case you have the styles:
Code: [Select]
csOwnerDrawEditableFixed,
csOwnerDrawEditableVariable
I have never used them, though, so I don't know how well (or if) they work.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 3077
Re: Make Combobox readonly for editing
« Reply #8 on: April 08, 2020, 04:24:30 pm »
Yes my point was has anyone tried changing those styles at runtime to make the box non or editable
 ?
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 7213
Re: Make Combobox readonly for editing
« Reply #9 on: April 08, 2020, 05:37:54 pm »
Code: [Select]
csOwnerDrawEditableFixed,
csOwnerDrawEditableVariable
I have never used them, though, so I don't know how well (or if) they work.
These styles are "editable" like csDropdown or csSimple: you can type text like in a TEdit. In addition they have the feature that the dropdown lines can be customdrawn. They work (at least on Windows - I just tested it).
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

zeljko

  • Hero Member
  • *****
  • Posts: 1141
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Make Combobox readonly for editing
« Reply #10 on: April 08, 2020, 06:48:04 pm »
Code: [Select]
csOwnerDrawEditableFixed,
csOwnerDrawEditableVariable
I have never used them, though, so I don't know how well (or if) they work.
These styles are "editable" like csDropdown or csSimple: you can type text like in a TEdit. In addition they have the feature that the dropdown lines can be customdrawn. They work (at least on Windows - I just tested it).

csOwnerDrawEditableFixed & csOwnerDrawEditableVariable works in Qt/Qt5 too ...
EDIT: and gtk2 too ...
« Last Edit: April 08, 2020, 06:52:30 pm by zeljko »

 

TinyPortal © 2005-2018