Forum > LCL

select item in TComboBoxEx

(1/2) > >>

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.

jamie:
I am not sure if I understand you. ?

Do you mean ItemIndexEx[aIndex_value].Caption := 'ijuioiodijoie' or something. ?

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)

jamie:

--- Quote from: RainerHamann on October 21, 2021, 10:35:24 pm ---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)

--- End quote ---

Ok, I got you now..

That control has design issues. The normal text has nothing in it..

I did a rework of that control way back but never posted it because I just kept finding more problems.

The Captions of each TItemList is not populated in the normal Tcombobox so things like the auto complete etc do not work.

You may do better if you simply use a normal TComboBox in owner draw mode and do your own drawing instead.

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.

Navigation

[0] Message Index

[#] Next page

Go to full version