Get text from specific TComboBox item if it's not selected - combobox

How do I get the text from a specific a specific TComboBox item if it's not selected. If I have a combobox with a list of three items and Item1 is the one currently selected:
0: 'ItemText1' (Item1)
1: 'ItemText2' (Item2)
2: 'ItemText3' (Item3)
The text from item 1 is with TComboBox.text is fairly easy, but how do I get the value of item 2 without selecting it? It should be quit easy but I tried various combinations but so far I have no luck (the Lazarus Component Library is currently down so I can't look it up there and all the examples I found used the selected item).
S.th. like "ShowMessage(TComboBox.Items[1].Text)" is what I'm looking for... (the output should be "Item2").

The Items property of a ComboBox is of type TStrings which behaves like a zero-based array of strings which you can read by supplying a numeric index. E.g.
ShowMessage(ComboBox1.Items[0]); // shows the first item, ItemText1 in your example
It works regardless of which item, if any, is selected in the gui.
Simple as that.

Related

Kendo UI for Angular combobox, filtering with two letters occasionally returns empty results

I did notice some weird behavior when filtering inside a combobox.
Entering a single letter works wine and narrows results, but here is what happens if I type t, and then tr, tra. What could be causing that?
Using backspace from tra to tr displays correct result.
Did notice that behavior in some other comboboxes on current screen.
Yes this is using Kendo-UI for Angular Combobox.
<form-combobox [data]="pickListData.activityTypes"
valueField="code"
textField="codeDescription"
[loading]="pickListDataLoading$ | async"
[defaultSelected]="0"
[filterable]="true"
[ngrxFormControlState]="formState.controls.activityType"></form-combobox>
By using [filterable]="true" you are stating that the list should be filterable. But you actually have to write a function like (filterChange)="handleFilter($event)" where you filter the data from the list based on the typed input.
If you want the kendo combobox to take care of filtering then you can simply use [kendoDropDownFilter] to which you can provide settings like if you want the search to be case sensitive and others.
Ref- https://www.telerik.com/kendo-angular-ui/components/dropdowns/combobox/filtering/

Codename One ComboBox how to highlighting already selected value

We are able to create ComboBox and populating data too. But we need to highlighting already saved values. Can you please suggest code for this.
Our requirement is if Combobox has 1,2,3. If I select 2 and save. We need to set the combo box value 2 in such way that when we open the Combobox need to display this 2 as highlight value along with 1,2,3 values.
Simply same as select box option selection.
I would generally recommend avoiding ComboBox altogether.
Assuming this isn't an option you will need to define a renderer and disable the OS specific 2 render mode using a theme constant:
otherPopupRendererBool=false

Create a dropdown box that contains numbers equal to or less than a number in another field

I am creating a database in Access 2013 for a library that has multiple copies of different books. I want to create a combo box/lookup list that displays numbers equal to or less than the total available copies of the book so that when a book is issued the librarian can select the next lowest value in the drop down. ( the number of available copies decreases by one). The number of purchased copies may change as the library buys more copies of the more popular books and so the drop down box needs to dynamically update. How do I do this? Do I need a replationship?
You first set the Combobox's RowSourceType Property to "Value List", to determine the combobox list is to be manually managed. then you use a Combobox's AddItem method method to add an item, and RemoveItem Method to remove an item. This is how you remove all items:
For i = 1 To ListBox1.ListCount
'Remove an item from the ListBox.
ListBox1.RemoveItem 0
Next i
After removing all current items, calculate how many Available Copies, and add them to the list in a loop:
For i = 1 To AvailableCopies
'Add an item from the ListBox.
ListBox1.AddItem i
Next i
Run this code for each book record presented, probably on OnCurrent event of a form.

Compatible value's position in an editable ComboBox

I have a ComboBox implemented with an auto-completion system. My ComboBox contains more than 100 items. When users are typing text in, the auto-completion system opens the dropdown list and highlights the most relevant item. Moreover, when the dropdown list is expanded, all items are available (no filters). But the most relevant item is always at the bottom of the dropdown list.
I would like it to be in the middle, if possible. One item can have the same reference but another type than another one, that's why I need to see most of them in my dropdown by placing them in the middle.
Any idea ? It's not really important but kind of useful for them. Thanks !
Update :
Here's my ComboBox with the open dropdown. Sorry about that, I had to blur its elements. As you can see, the user starts writting the reference in the ComboBox. The autocompletion works fine, but the corresponding item is found at the end of the dropdown list (in the red frame), almost out of bounds.
I wish it would be highlighted in the middle of my dropdown list instead of so far below.
Your item search may work well, but your list isn't visually filtered, which means it's size always remains the same.
It's scrolled into view, by the wpf system, but still displaying all other items around the relevant one. The reason why it's at the bottom is because wpf Scrollviewer just finished scrolling the item into view and sees no need to scroll it further into the middle.
You could use the CollectionViewSource class. Why ?
It's simple to use, will keep your viewmodel data as it is, and you would have your relevant completion item at the top. It can be obtained by GetDefaultView(..)
Let's say you have a viewmodel flag "IsHidden", stating that it's content does not match the user input:
ICollectionView cv= CollectionViewSource.GetDefaultView(myComboBox.ItemsSource);
// switch filter on
cv.Filter = obj => (obj as myViewModel).IsHidden == false;
// switch off
cv.Filter = null

ComboBox selection not reset to top of dropdown list (items) in javafx 2.2

I have a Source ComboBox to populate source fields (25-30 items) shown below in first page
"A"
"B"
...
"Z"
I have selected last item from ComboBox as shown below
"Z"
and when traversing to the next page after saving, i need to make the source combo selection blank, so i have return the below code to reset the Source combobox to point to first item (to reset the display to start from top of dropdown list for user selection)
// my first value in source List is empty space - “”
sourceComboBox.setValue("");
even if you use below code snippets like
sourceComboBox.getSelectionModel().selectFirst();
sourceComboBox.getItems().clear();
sourceComboBox.getSelectionModel().clearAndSelect(0);
but when i click open the combobox dropdown it still shows dropdown display from bottom as shown below
...
"X"
"Y"
"Z"
I am unable to post images for representing combobox values, so has put in above examples.
This looks like a graphics bug to me or am I doing something wrong?
I have seen similar issue reported in below question but no work around suggested so far
Combobox clearing value issue
If you want to simply "reset" the combo box, I think all you have to do is set the value to null, like so:
sourceComboBox.setValue(null);
I ran into nearly the exact same situation and came across your question while looking for a solution. Fortunately, I came up with a workaround that forces the ComboBoxes to reset. When you reset the data on your pane, instead of doing something like:
sourceComboBox.getSelectionModel().clearSelection();
sourceComboBox.getItems.clear();
do something like this...
parentNode.getChildren().remove(sourceComboBox);
sourceComboBox= new ComboBox(); // do whatever else you need to format your ComboBox
parentNode.add(sourceComboBox);
You'll also need to do a setItems() again on your ComboBox so the new one will be populated. This is not an ideal solution but it seems to be working as I expect the provided clearSelection() method would.
Below is the code you're looking for. It will reset it to whatever index you give in within the parenthesis.
sourceComboBox.setSelectedIndex(0);
Goodluck
Most of the things were giving me an error when I tried them. What worked best for me was to use this
comboBox.getSelectionModel.clearSelection();
This will essentially set the value of your ComboBox to null. Because of this, if you are referring to the value of the ComboBox in another place, it becomes important to check for whether the value of the ComboBox is null using this
if(comboBox.getValue() != null)
//Code segment here
The ComboBox control has not a method like scrollTo(index) of the ListView. So it seems hard to workaround that behavior. You can issue a feature request at JavaFX Jira.

Resources