Solved

tComboBox with unselecteble items

Posted on 2011-02-17
4
324 Views
Last Modified: 2012-05-11
I want to add something like:

--------------------
New Item

at the end of the itemlist in a ComboBox and the next to the last line the "--------------------" should not be selectable, is there any way to do this?
0
Comment
Question by:Sunsales
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Assisted Solution

by:KoenVandemoortel
KoenVandemoortel earned 83 total points
ID: 34918623
The only thing I can think of is something like this:
procedure TForm1.ComboBox1Select(Sender: TObject);
begin
if ComboBox1.Text='--------' then Combobox1.ClearSelection;
end;

Open in new window

0
 

Author Comment

by:Sunsales
ID: 34918638
Not to bad! - I will look into it.
0
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 84 total points
ID: 34919589

Use the OnCloseUp Event
procedure TForm1.ComboBox1CloseUp(Sender: TObject);
var
  Index: Integer;
begin
  Index := ComboBox1.ItemIndex;
  if (Index >= 0) and (Pos('--', ComboBox1.Items[Index]) = 1) then
    ComboBox1.ItemIndex := -1;
end;

Open in new window

0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 83 total points
ID: 34923617
Using OnChange event...
procedure TForm1.ComboBox1Change(Sender: TObject);
var
  s:string;
begin
  s:=(sender as TComboBox).Text;
  if pos('-----',s)>0 then (sender as TComboBox).ItemIndex:=-1;
end;

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month5 days, 3 hours left to enroll

635 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