Home › Forums › Konopka Signature VCL Controls (formerly Raize Components) › TRzComboBox › Reply To: TRzComboBox
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