Home › Forums › Konopka Signature VCL Controls (formerly Raize Components) › TRzComboBox
- This topic has 3 replies, 2 voices, and was last updated 2018-10-05 at 2:48 am by Ray Konopka.
-
AuthorPosts
-
-
September 14, 2018 at 10:54 am #397
Hi Ray .. I am pretty new with your components and I am trying to use the ComboBox .
After adding lines to this combobox with the AddItemValue property, how can I access
the value of the selected item ??Many thanks
Best Regards
-
September 16, 2018 at 12:20 am #398
Hi,
You can simply use the Value property of the combo box. If an item in the combo box is selected then the Value property returns the corresponding value for that item. If no item is selected, then Value returns an empty string.Ray
-
September 18, 2018 at 7:57 am #402
Hi Ray, thanks for the answer, but can you help me please to do that ?
Assuming that I have 10 rows with String and value for each in the combo, how can I retrieve the value for the selected row ??
I’ve addes lines to the combo this way.
Combobox.AddValue( ‘string1’, 1 )
Combobox.AddValue( ‘string2’, 2 ) and so on..How can I retrieve the value 2 for the second row if selected ??..
Maybe its combobox.items[combo.itemindex].value ?? did not try it..just thinking..
Thanks so much.
-
October 5, 2018 at 2:48 am #406
I apologize for the delay in responding. I did not realize you asked a follow-up question. Consider the following code. I have dropped a TRzComboBox, a TRzButton, and a TRzLabel onto a form.
procedure TForm29.FormCreate(Sender: TObject); begin RzComboBox1.AddItemValue( 'Item One', '1' ); RzComboBox1.AddItemValue( 'Item Two', '2' ); RzComboBox1.AddItemValue( 'Item Three', '3' ); RzComboBox1.AddItemValue( 'Item Four', '4' ); RzComboBox1.AddItemValue( 'Item Five', '5' ); end;
The above code adds several items and values to the list. You can get the Values by using the Values list property. For example:
procedure TForm29.RzButton1Click(Sender: TObject); begin RzLabel1.Caption := RzComboBox1.Values[ RzComboBox1.ItemIndex ]; end;
But the problem with this approach is that you need to protect against ItemIndex being -1, which will lead to an Index Out Of Bounds exception. A better approach is to simply use the Value property as shown below:
procedure TForm29.RzButton1Click(Sender: TObject); begin RzLabel1.Caption := RzComboBox1.Value; end;
Ray
-
-
AuthorPosts
- You must be logged in to reply to this topic.