Board index » cppbuilder » probably another stupid question on ComboBoxes

probably another stupid question on ComboBoxes


2003-09-22 01:21:37 PM
cppbuilder30
hello everyone! :)
i was wondering if there's any way for me to set a TComboBox's style property to csDropDownList but still be able to set it's Text property?
i want to make the text property of the combobox readonly. and i also want to set it to a string that may or may not be included in the combobox's items. this way i can provide a default value (even if it is not included in the items).
i would really, really appreciate any help.
thanks.
 
 

Re:probably another stupid question on ComboBoxes

"mickey" < XXXX@XXXXX.COM >wrote in message
Quote
i was wondering if there's any way for me to set a TComboBox's style
property to csDropDownList but still be able to set it's Text property?
No, because the Text property works with the ComboBox's edit field, which
does not exist when using csDropDownList. The whole point of
csDropDownList's design is that it does not allow the user to type in a
value manually, but must use the drop-down list only.
Quote
and i also want to set it to a string that may or may not be included in
the combobox's items.
When using csDropDownList, you can't set it to an item that does not already
exist in the list.
Quote
this way i can provide a default value (even if it is not included in the
items).
What you ask for can't be done with csDropDownList.
What's wrong with simply testing the ItemIndex for -1 when you go to
retreive the selected item, and then using a default value in your code when
appropriate?
AnsiString value;
int index = ComboBox1->ItemIndex;
if( index>-1 )
value = ComboBox1->Items->Strings[index];
else
value = "some default value";
Gambit
 

Re:probably another stupid question on ComboBoxes

mickey < XXXX@XXXXX.COM >wrote:
Quote

what i really wanted to do, is show a default Text on the combobox, even if
this text is not one of the items. The text should be readonly and will only
change when the user selects a new item.
Why not just have the first item in the list be the default text?
i.e.
comboBox->Items->Assign(myCars);
comboBox->Items->Insert(0, "Select a car...");
comboBox->ItemIndex = 0;
The only drawback is that the default text will appear in the drop down
list. (But that shouldn't be an issue since lots of ComboBoxes work like
that)
-- darren
 

{smallsort}

Re:probably another stupid question on ComboBoxes

Quote
Why not just have the first item in the list be the default text?
oh! how i would wish i could do that!
but no, i cant. whaaaaa! :(
the default text that i set may or may not be one of the items.
if this is impossible, then i believe i have to resort to my other choice: plead to my trainor. hehehe. :)
 

Re:probably another stupid question on ComboBoxes

"mickey" < XXXX@XXXXX.COM >wrote in message
Quote
what i really wanted to do
<snip>
I understood what you wanted. It cannot be done with csDropDownList, there
is no edit field available to set any Text for. Period. You'll just have
to do something else with your UI to get around it.
Gambit
 

Re:probably another stupid question on ComboBoxes

"mickey" < XXXX@XXXXX.COM >wrote in message
Quote
oh! how i would wish i could do that!
but no, i cant. whaaaaa! :(
Why not?
Gambit