2

I would like that on a TCombobox the only way to change a value is by using the mouse.

If the Items are 1,2 and 3 the user can type 4 and it becomes the value.

i tried to use OnKeyDown but somehow i would like to "avoid key down". How to achieve this?

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249

1 Answers1

10

Set TCombobox.Style into csDropDownList, so user would choose only predefined items

MBo
  • 77,366
  • 5
  • 53
  • 86
  • Thanks. In this way runtime management must rely on TComboBox.ItemIndex and not on tComboBox.Text but it works as expected. – UnDiUdin Mar 10 '17 at 14:02
  • **In this way runtime management must rely on TComboBox.ItemIndex and not on tComboBox.Text** ...which is better as it uses integer comparisons instead of string comparisons. – Uli Gerhardt Mar 10 '17 at 14:28
  • I'd say "not necessarily" to both of the above comments. The Items list is a TStrings list, and you can search with IndexOf('a string') or use ItemIndex or just the value of Text. It really depends on what you want. It's very flexible. And don't forget there's also the Items.Objects[] property that lets you associate an object with each item. – David Schwartz Mar 11 '17 at 04:02
  • It doesn't seem to work correctly with csDropDownList on 10.2 for whatever reason. Whether you specify it ahead of time or change it through ItemIndex/Text property. – RoughTomato Aug 28 '19 at 01:50
  • @RoughTomato I did not noticed any changes in work with csDropDownList on 10.2 – MBo Aug 28 '19 at 01:59
  • @MBo after some thinking it might be desired behavior, when I go through it with debugger both text and ItemIndex are set correctly, CB is still empty though. Nothing in the implementation suggests that this is a bug of any kind so it doesn't matter :) I'll deal with it on my end – RoughTomato Aug 28 '19 at 03:11