Forum > LCL

select item in TComboBoxEx

(1/1)

RainerHamann:
I want to set and select items of TComboBoxEx dependend from other user action like TComboBox.ItemIndex:=... and ShowMessage(TComboBox.Text), but there is nothing like e.g. ItemIndexEx or TextEx to set or read both properties.

I'm using Lazarus 2.2.0RC1 with QT5 property set for my project on Linux Mint.

RainerHamann:
No, I want to show one line (icon and text) in the extended ComboBox. With a standard ComboBox I would do
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---cb.ItemIndex:=3 and I want to read the text of the by the user selected line like
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---some var := cb.Text (standard ComboBox)

wp:
The ItemIndex works for TComboBoxEx in the same way as for TComboBox:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  ComboBoxEx1.ItemIndex := 1;  // Select the 2nd item (having index 1)Retrieving the item caption is a bit more complicated since the property ItemsEx[index] returns the full item instance at the given index. But there's a property Caption for the text of of that item:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- ShowMessage(ComboBoxEx1.ItemsEx[CombBoxEx1.ItemIndex].Caption);Other properties of the ItemsEx[index] are:
- ImageIndex
- OverlayImageIndex
- SelectedImageIndex
- Indent
(Just what is available when you populate the items by the '...' button next to ItemsEx in the object inspector).

Unlike a TCombobox which is populated by calling ComboBox1.Add(text_of_the_item) you populate the TComboBoxEx at runtime  this way:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---with ComboBoxEx1.ItemsEx.Add dobegin  Caption := text_of_the_item;  ImageIndex := 15;  SelectedImageIndex := 15;end; // or quicker, if you only want to set the captionComboBox1.ItemsEx.Add.Caption := text_of_the_item;
The property Text is not available since the displayed text cannot be edited. I don't know why it is published.

RainerHamann:
Okay, thank you very much!

Navigation

[0] Message Index

Go to full version