Board index » delphi » Setting Text property in TComboBox

Setting Text property in TComboBox

Hi,
I try to make a TComboBox where the user shall have the possibility to
choose between a number of alternatives, but not be able to enter anything
else in the TComboBox. I almost solved this by setting Style to
csDropDownList, but then I am not able to set a initial value in the
TComboBox by setting the Text property.

Can anybody explain to me why the text property doesn't get any value by the
statement
ComboBox1.Text:= 'Value';
if Style is set to csDropDownList. When Style is csDropDown, the Text
property get its value.

I am confused!!

 

Re:Setting Text property in TComboBox


When you set the TComboBox to csDropDownList, it ceases to
respond to commands to set it's text property directly. This
is by design. Use the Items property to set it to the
desired value:

    MyDropDown.ItemIndex :=
MyDropDown.Items.IndexOf(InitialValue);

HTH
Woody

"Bengt H?kansson" <Bengt.Hakans...@vv.slu.se> wrote in
message news:3b4a2e16_2@dnews...

Quote
> Hi,
> I try to make a TComboBox where the user shall have the
possibility to
> choose between a number of alternatives, but not be able
to enter anything
> else in the TComboBox. I almost solved this by setting
Style to
> csDropDownList, but then I am not able to set a initial
value in the
> TComboBox by setting the Text property.

> Can anybody explain to me why the text property doesn't

get any value by the
Quote
> statement
> ComboBox1.Text:= 'Value';
> if Style is set to csDropDownList. When Style is

csDropDown, the Text
Quote
> property get its value.

> I am confused!!

Re:Setting Text property in TComboBox


Quote
Woody wrote:
> When you set the TComboBox to csDropDownList, it ceases to respond to
> commands to set it's text property directly. This is by design. Use
> the Items property to set it to the desired value:
>     MyDropDown.ItemIndex := MyDropDown.Items.IndexOf(InitialValue);

However, if you wish the initial text to be something like '<Choose from
this list>' you might try this: (untested)

Set the Style to csDropDown.
Set the Text.
Set the Style to csDropDownList.

--Doug

Other Threads