Board index » delphi » Combobox.Text

Combobox.Text

Hi.
This sounds like a simple task, but I'm stuck.

I can give an initial text value to a combobox
component inside Delphi by setting the text
property to something like "Please select.."..

At runtime, when a user selects something
from the combobox, after running some code,
I want the combobox to get to it's initial state
and show "Please select.." again.

I try to set the text property like this, but this
only makes the combobox text to show nothing..
Also no errors..

Combobox1.itemindex:= -1;
Combobox1.text:= "Please select..";

I think this sould be implemented in
an "easier to use" way..

Thanks in advance

 

Re:Combobox.Text


Quote
>Arda Tunccekic wrote:

> Combobox1.itemindex:= -1;
> Combobox1.text:= "Please select..";

What is the Style of the ComboBox set to?
________
Andreas
Delphi 5.01 Pro, NT4 Sp6a
Direct replies mailto:paw...@gmx.net

Re:Combobox.Text


Quote
> > Combobox1.itemindex:= -1;
> > Combobox1.text:= "Please select..";
> What is the Style of the ComboBox set to?

It's set to csDropDown which is the default style. Shouldn't it be??

Re:Combobox.Text


Quote
In article <3b594386_2@dnews>, Arda Tunccekic wrote:
> This sounds like a simple task, but I'm stuck.
> I can give an initial text value to a combobox
> component inside Delphi by setting the text
> property to something like "Please select.."..
> At runtime, when a user selects something
> from the combobox, after running some code,
> I want the combobox to get to it's initial state
> and show "Please select.." again.
> I try to set the text property like this, but this
> only makes the combobox text to show nothing..
> Also no errors..

> Combobox1.itemindex:= -1;
> Combobox1.text:= "Please select..";

If your combobox has style csDropDown simply do not set the item index.
You need this style to be able to show text in the box that is not in
the list. On the other hand this enables to user to enter arbitrary
text as well, which gets in the way if you only want him/her to pick an
existing item from the list (csDropDownList). I would use the combobox
Hint property to show the "Please select" text, not put it into the
combobox itself. This allows you to use csDropDownList.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:Combobox.Text


Quote
"Peter Below (TeamB)" wrote:
> I would use the combobox Hint property to show the "Please select" text,
> not put it into the combobox itself. This allows you to use
> csDropDownList.

How about using the csDropDown style until the user enters the ComboBox
then switch to csDropDownList?  When you want ro reset the text switch back
to csDropDown.

--Doug

Re:Combobox.Text


Quote
In article <3B59966F.25FD5...@mpinet.net>, Douglas J. Horton wrote:
> How about using the csDropDown style until the user enters the ComboBox
> then switch to csDropDownList?  When you want ro reset the text switch back
> to csDropDown.

That has a big problem. Changing the style will destroy and recreate the
controls window handle. If you do that in the middle of a focus change
(OnEnter, OnExit) you'll confuse Windows big time, probably ending up with no
control having focus.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:Combobox.Text


Quote
"Peter Below (TeamB)" wrote:
> That has a big problem. Changing the style will destroy and recreate the
> controls window handle. If you do that in the middle of a focus change
> (OnEnter, OnExit) you'll confuse Windows big time, probably ending up with no
> control having focus.

Yikes!  Thanks for the info.

--Doug

Re:Combobox.Text


Quote
"Arda Tunccekic" <a...@duzen.com.tr> wrote in message

news:3b594386_2@dnews...

Quote
> I can give an initial text value to a combobox
> component inside Delphi by setting the text
> property to something like "Please select.."..

> At runtime, when a user selects something
> from the combobox, after running some code,
> I want the combobox to get to it's initial state
> and show "Please select.." again.

A common work-around is to use csDropDownList style and set the text of the
first item as "<Select One>" or similar.  Resetting is no problem of course.
Here's an example on Creatives' site -
http://www.creative.com/support/files/download.asp

--
Regards,
Chris Luck

Re:Combobox.Text


Thank you very much for the info.

I'd like to add this.
I tried the code below with Delphi6 , and it works.
But of course, it doesn't work with Delphi 3...

Combobox1.text:= "Please select..";

Arda

Other Threads