ComboBox.ItemIndex

How can i do that below proc.

SearchText:='All';

if searchText exists in ComboBox1 then
Show searchtext in combobox

else
begin
ComboBox1.Items.Add('searchtext')
Show searchtext in combobox
end;

Thank You
0
Melissa
1/4/2012 8:08:57 AM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

3 Replies
2843 Views

Similar Articles

[PageSpeed] 5

Melissa Torn wrote:

> How can i do that below proc.
> 
> SearchText:='All';
> 
> if searchText exists in ComboBox1 then
> Show searchtext in combobox
> 
> else
> begin
> ComboBox1.Items.Add('searchtext')
> Show searchtext in combobox
> end;

ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(searchText);
if(ComboBox1.ItemIndex = -1)then begin
   ComboBox1.ItemIndex := ComboBox1.Items.Add(searchText);
end;


HTH
ain
0
Ain
1/4/2012 8:24:57 AM
Thank you so much Ain,

But you dont search 
if searchtext exists or not in the combobox ?
your code   if(ComboBox1.ItemIndex = -1)then
means if anything exists in combobox ?? 

I first need if searchtext exists in combobox
or not,  if exists then select the searchtext in combobox
if not exist i'll add it into the combobox and select it


> {quote:title=Ain Valtin wrote:}{quote}
> Melissa Torn wrote:
> 
> > How can i do that below proc.
> > 
> > SearchText:='All';
> > 
> > if searchText exists in ComboBox1 then
> > Show searchtext in combobox
> > 
> > else
> > begin
> > ComboBox1.Items.Add('searchtext')
> > Show searchtext in combobox
> > end;
> 
> ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(searchText);
> if(ComboBox1.ItemIndex = -1)then begin
>    ComboBox1.ItemIndex := ComboBox1.Items.Add(searchText);
> end;
> 
> 
> HTH
> ain
1
Melissa
1/4/2012 8:55:10 AM
Melissa Torn wrote:

> But you dont search 
> if searchtext exists or not in the combobox ?

It does - the "ComboBox1.Items.IndexOf(searchText)" statement search
the items list for "searchText" and returns it's index, if there is no
match then the return value is "-1".


> your code   if(ComboBox1.ItemIndex = -1)then
> means if anything exists in combobox ?? 

In this case it means "if there wasn't matching item". The ItemIndex -1
means that no item is selected.


ain
0
Ain
1/4/2012 9:07:58 AM
Reply:

Web resources about - ComboBox.ItemIndex - embarcadero.delphi.general

Juhani Lehtimäki – Google+
Juhani Lehtimäki - Android developer, design fan and author of Smashing Android UI book, co-creator of Lands of Ruin. - Head of Android development ...

Creating a unique ListView layout using cell-spanning
... defaultSize: { width: 100, height: 100 } }; // Item info function that returns the size of a cell spanning item function myItemInfo(itemIndex) ...

Maor's Blog
Maor David's Blog - A blog by Maor David specializes in dot net ( .NET) framework, posts about .net, asp.net, c#, ajax. http://blog.maordavid.com ...

XBot scripting
List of methods for developing scripts in XBot.

Fully Editable Datagrid - Pale Musings
This is the text from an article I wrote back in April of 2003 and had published on the original DotNetJunkies site. After my recent change in ...

jQuery and WinJS working together in Windows Store apps
... ListView with the following code: // Get the data for the selected item in the list view. function getItem(evt) { var index = evt.detail.itemIndex, ...

Resources last updated: 3/2/2016 4:05:24 PM