Solved

Default value for TComboBox

Posted on 1998-09-27
4
664 Views
Last Modified: 2010-04-03
Delphi3, NT40 - I have a TComboBox of type csDropDownList.  It has two values, All and Selected.  What I'm trying to do is to set a value in the combobox when the form opens.  I can't seem to do this.  I have tried setting the value of Text in the Object inspector.  It simply disappears when I move to another column in the object inspector. (It only does this when Type is set to csDropDownList).

I have tried programatically (On Form Activate) to set:

ComboBox.Text := 'All';
as well as
ComboBox.SelText := 'All';

Neither worked.  How do I set this value?

Thanks
0
Comment
Question by:gspears060598
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:binkzz
ID: 1340972
The default text you want in your combo list has to already exist
in the actual list seeing it is of type csdropdownlist. Therefore
make sure it has got a value, then set the itemindex property
to the value you want.

Binkzz
0
 
LVL 10

Accepted Solution

by:
viktornet earned 20 total points
ID: 1340973
You could do only ComboBox1.Text := 'Hello';

or you could do....

ComboBox1.Items.Add('Hello');
Combobox1.ItemIndex := 0;

Regards,
Viktor Ivanov
0
 
LVL 4

Expert Comment

by:binkzz
ID: 1340974
viktornet:

Read the question better next time;
the first solution you gave was something already proven
ineffective, the second was already given by me.

You were not sure if it would work as well, then why send it as
an answer?

Read the questions and the comments properly before you recogn
you can get some points. If you have a good answer, it will be
awarded, whether send as a comment or an answer. In fact, if
send as a comment rather than an answer usually gets you more
points as it is not as arrogant.

Binkzz
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1340975
Why don't you stop bothering me??or is it easier for you that way......???

Here is an improvement....

OnCreate() of the form

ComboBox1.Items.Add('Hello');
ComboBox1.ItemIndex := ComboBox1.Items.IndexOf('Hello');

Regards,
Viktor Ivanov
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question