Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to remove TComboBox selection?



Permlink Replies: 18 - Last Post: Aug 10, 2015 1:06 PM Last Post By: Bo Berglund
Bo Berglund

Posts: 757
Registered: 10/23/02
How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 7, 2015 11:11 PM
I have an application to maintain developed in BDS2006. Now migrated
to XE5.
It contains a configuration window with multiple tabs and here are a
number of controls for parameter selection. One type of component is
causing problems because in some instances its content is selected
causing the text to get a dark blue background. The selection cannot
be removed except by manually going to the control and putting the
cursor on the entry. Then it is deselected and the text can be read
properly. But some controls are enabled only depending on the setting
of another control, so if that is in the state that disables the entry
box then the selection won't go away at all.

The component is a descendant of TComboBox called TNumComboBox by the
author and the changes from the standard TComboBox is shown here:
type
  TNumComboBox = class(TComboBox)
  protected
    procedure Change; override;
  end;
 
procedure Register;
 
implementation
function StrToFloatUS(sVal: string): Double;
{This function converts a string to float using the decimal separator
..
If the string contains illegal characters they are removed first.
If the conversion results in an exception then return 0}
var
  c: char;
  i: integer;
  Fmt: TFormatSettings;
begin
  {$IF CompilerVersion >= 26} {Delphi XE5..}
    Fmt := TFormatSettings.Create;
  {$IFEND}
  Fmt.DecimalSeparator := '.';
  {Scan string for illegal characters, replace comma with . etc}
  sVal := Trim(LowerCase(sVal));
  for i := Length(sVal) downto 1 do
    if sVal[i] = ',' then
      sVal[i] := '.';
  try
    if sVal = '' then
      Result := 0
    else
      Result := StrToFloat(sVal, Fmt);
  except
    Result := 0;
  end;
end;
 
procedure TNumCombobox.Change;
begin
  Inherited Change;
  try
    StrToFloatUS(Text);
  except
    on EConvertError do
    begin
      Text := '';
    end;
  end;
end;
 
procedure Register;
begin
  RegisterComponents('MyCustomCmp', [TNumComboBox]);
end;


In the main code the comboboxes get filled from the forms designer and
there are also places where its text property is being set by direct
writing in code to the control. This happens when some data files are
loaded for example.
The enabling and disabling of the TNumCombobox is done as follows
(cbxForwSolver is a regular TComboBox whereas cbxForwCGIter and
cbxForwCGResid are TNumComboBox objects):
procedure TfrmSettings.cbxForwSolverChange(Sender: TObject);
begin
    if cbxForwSolver.ItemIndex = 0 then begin
        cbxForwCGIter.Enabled := false;
        cbxForwCGResid.Enabled := false;
    end else begin
        cbxForwCGIter.Enabled := true;
        cbxForwCGResid.Enabled := true;
    end;
end;


Any idea how I could deselct the text in the TNumComboBox in code?

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572

Bo Berglund

Posts: 757
Registered: 10/23/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 12:39 AM   in response to: Bo Berglund in response to: Bo Berglund
I might add that I checked the various properties and methods of the
TComboBox class and especially ClearSelection looked promising by the
name at least. However, what it does is setting ItemIndex = -1 and the
Text property to an empty string, not exactly what I need...
I just want to remove the selection coloring just as if I had placed
the cursor at the end of the text in the box or similar.
But doing this in code....

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 12:45 AM   in response to: Bo Berglund in response to: Bo Berglund
And setting SelStart only works if the control has focus, which of
course is not possible for a disabled control...

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572

Peter Below

Posts: 1,227
Registered: 12/16/99
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 3:32 AM   in response to: Bo Berglund in response to: Bo Berglund
Bo Berglund wrote:

I have an application to maintain developed in BDS2006. Now migrated
to XE5.
It contains a configuration window with multiple tabs and here are a
number of controls for parameter selection. One type of component is
causing problems because in some instances its content is selected
causing the text to get a dark blue background. The selection cannot
be removed except by manually going to the control and putting the
cursor on the entry. Then it is deselected and the text can be read
properly. But some controls are enabled only depending on the setting
of another control, so if that is in the state that disables the entry
box then the selection won't go away at all.

Is this perhaps the ActiveControl of the form? Make sure you set this
form property to a control that will not be disabled during form load.
If the form is shown modally, set the PopupMode property to pmAuto.

--
Peter Below (TeamB)

Bo Berglund

Posts: 757
Registered: 10/23/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 5:56 AM   in response to: Peter Below in response to: Peter Below
On Sat, 8 Aug 2015 03:32:19 -0700, Peter Below <none@address.invalid>
wrote:

Is this perhaps the ActiveControl of the form? Make sure you set this
form property to a control that will not be disabled during form load.

The configuration form has a number of tabs and the form's
ActiveControl property is empty as far as I can see.
I have never used this property before, what good is it?
I tried to set its value to the Ok button just as a test, but there
was no change in behaviour.

If the form is shown modally, set the PopupMode property to pmAuto.
The form is shown as follows:
procedure TfrmMain.mitCRPSettingsClick(Sender: TObject);
begin
  frmSettings.GetLagrangeDamp0; //Reads avalues in some controls into
variables
  frmSettings.Show;
end;

As you can see it is not shown modally at all (which is a usability
problem all by itself). And the PopUpMode property of the form is
pmNone.

Note that there are several controls of the same kind in the form but
not all of them does this. In fact there is a control on the main form
(beside the tool bar) which is rather seldom used but this too shows a
selected text when the application starts running and it is not
possible to get rid of the selection and hence it sticks out even
though the combo is mostly disabled.

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572

Peter Below

Posts: 1,227
Registered: 12/16/99
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 7:06 AM   in response to: Bo Berglund in response to: Bo Berglund
Bo Berglund wrote:

On Sat, 8 Aug 2015 03:32:19 -0700, Peter Below <none@address.invalid>
wrote:

Is this perhaps the ActiveControl of the form? Make sure you set
this form property to a control that will not be disabled during
form load.

The configuration form has a number of tabs and the form's
ActiveControl property is empty as far as I can see.
I have never used this property before, what good is it?

It defines which control will get the focus when the form is shown the
first time. If you leave it empty at design-time then the first
focusable control in tab order will get the focus. Once the form is up
this property gives you the control currently with focus, and you can
set it to move the focus in code.

I tried to set its value to the Ok button just as a test, but there
was no change in behaviour.

If the form is shown modally, set the PopupMode property to pmAuto.
The form is shown as follows:
procedure TfrmMain.mitCRPSettingsClick(Sender: TObject);
begin
  frmSettings.GetLagrangeDamp0; //Reads avalues in some controls into
variables
  frmSettings.Show;
end;

As you can see it is not shown modally at all (which is a usability
problem all by itself). And the PopUpMode property of the form is
pmNone.

Note that there are several controls of the same kind in the form but
not all of them does this. In fact there is a control on the main form
(beside the tool bar) which is rather seldom used but this too shows a
selected text when the application starts running and it is not
possible to get rid of the selection and hence it sticks out even
though the combo is mostly disabled.

It can be problematic if you change the enabled state of controls
during the form load, or when the control does not have a handle yet
(can happen for controls on tabsheets other than the active one, for
example). Try to call the control's HandleNeeded function before you
modify its content or state in code, perhaps that fixes the problem.

It seems to be something you only run into with combo boxes having the
csDropdown style (= editable by the user). I have never seen it in my
own applications, but I practically only use csDropdownList comboboxes.

--
Peter Below (TeamB)

Douglas Rudd

Posts: 314
Registered: 5/16/97
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 7:45 AM   in response to: Bo Berglund in response to: Bo Berglund
You didn't say if the user fills in these comboboxes by picking on the dropdown list or he types in a number in the combobox.

If he just fills them in by picking from the list then you should set the Style property to csDropdownList. Then the combobox text never gets selected or turns blue.
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 12:20 PM   in response to: Douglas Rudd in response to: Douglas Rudd
On Sat, 8 Aug 2015 07:45:21 -0700, Douglas Rudd <> wrote:

You didn't say if the user fills in these comboboxes by picking on the dropdown list or he types in a number in the combobox.

I am not sure, normally I think a number is chosen from the list. But
it may also be the case that in some circumstances a new value is
typed in.
I'll have to ask the application guys about that. I don't expect to
get a reply until Monday though...

If he just fills them in by picking from the list then you should set the Style property to csDropdownList. Then the combobox text never gets selected or turns blue.

Right, that is how I usually program combo boxes. But this is anoter
guy's creation and I am just maintaining it (upgrading to XE5 and
introducing Unicode text for internationalization).

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572

Peter Below

Posts: 1,227
Registered: 12/16/99
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 10, 2015 12:58 AM   in response to: Bo Berglund in response to: Bo Berglund
Bo Berglund wrote:

On Sat, 8 Aug 2015 03:32:19 -0700, Peter Below <none@address.invalid>
wrote:

Is this perhaps the ActiveControl of the form? Make sure you set
this form property to a control that will not be disabled during
form load.

The configuration form has a number of tabs and the form's
ActiveControl property is empty as far as I can see.
I have never used this property before, what good is it?

It defines which control will get the focus when the form is shown the
first time. If you leave it empty at design-time then the first
focusable control in tab order will get the focus. Once the form is up
this property gives you the control currently with focus, and you can
set it to move the focus in code.

I tried to set its value to the Ok button just as a test, but there
was no change in behaviour.

If the form is shown modally, set the PopupMode property to pmAuto.
The form is shown as follows:
procedure TfrmMain.mitCRPSettingsClick(Sender: TObject);
begin
  frmSettings.GetLagrangeDamp0; //Reads avalues in some controls into
variables
  frmSettings.Show;
end;

As you can see it is not shown modally at all (which is a usability
problem all by itself). And the PopUpMode property of the form is
pmNone.

Note that there are several controls of the same kind in the form but
not all of them does this. In fact there is a control on the main form
(beside the tool bar) which is rather seldom used but this too shows a
selected text when the application starts running and it is not
possible to get rid of the selection and hence it sticks out even
though the combo is mostly disabled.

It can be problematic if you change the enabled state of controls
during the form load, or when the control does not have a handle yet
(can happen for controls on tabsheets other than the active one, for
example). Try to call the control's HandleNeeded function before you
modify its content or state in code, perhaps that fixes the problem.

It seems to be something you only run into with combo boxes having the
csDropdown style (= editable by the user). I have never seen it in my
own applications, but I practically only use csDropdownList comboboxes.

--
Peter Below (TeamB)

Carl-Henrik Nil...

Posts: 53
Registered: 3/26/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 10, 2015 4:28 AM   in response to: Peter Below in response to: Peter Below
Peter Below wrote:
It seems to be something you only run into with combo boxes having the
csDropdown style (= editable by the user). I have never seen it in my
own applications, but I practically only use csDropdownList comboboxes.

I've never seen it before either, but I can reproduse it with XE5 on Win7 now that I'm sure about what happens and when:

- Drop a TComboBox on a form
- Set the syle to csDropDown
- Add some Items
- Set ItemIndex to an Item
- Set Enabled to False

Run, and the ComboBox turns up with blackish text against a blue background - hard to read.
--
C-H
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 10, 2015 1:06 PM   in response to: Carl-Henrik Nil... in response to: Carl-Henrik Nil...
On Mon, 10 Aug 2015 04:28:06 -0700, Carl-Henrik Nilsson <> wrote:

Peter Below wrote:
It seems to be something you only run into with combo boxes having the
csDropdown style (= editable by the user). I have never seen it in my
own applications, but I practically only use csDropdownList comboboxes.

I've never seen it before either, but I can reproduse it with XE5 on Win7 now that I'm sure about what happens and when:

- Drop a TComboBox on a form
- Set the syle to csDropDown
- Add some Items
- Set ItemIndex to an Item
- Set Enabled to False

Run, and the ComboBox turns up with blackish text against a blue background - hard to read.

And your suggested way to deselect the text in the disabled CB works!
:)

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572
Carl-Henrik Nil...

Posts: 53
Registered: 3/26/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 9:29 AM   in response to: Bo Berglund in response to: Bo Berglund
Bo Berglund wrote:
<snip>
Any idea how I could deselct the text in the TNumComboBox in code?

I'm not sure about your scenario or when you want to remove the selection in the edit child control
of the ComboBox, but normally sending a CB_SETEDITSEL message to the ComboBox is the way to do it:

SendMessage(SomeComboBox.Handle, CB_SETEDITSEL, 0, 0);

Normally setting Enabled to False will also remove the selection.

If sending a CB_SETEDITSEL message doesn't work in your scenario, then you could instead try toggling
the Enabled state, possibly a couple of times if needed.

For example, if the ComboBox is Enabled:
SomeComboBox.Enabled := False; //Removes the selection
SomeComboBox.Enabled := True; //Enabled and still no selection

The toggling isn't noticeable.

Remove the selection wherever you feel it's needed - in an OnChange or OnEnter event handler, for instance.
--
C-H
Carl-Henrik Nil...

Posts: 53
Registered: 3/26/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 11:12 AM   in response to: Carl-Henrik Nil... in response to: Carl-Henrik Nil...
Carl-Henrik Nilsson wrote:
Remove the selection wherever you feel it's needed - in an OnChange or OnEnter event handler, for instance.

Oops, That doesn't work. Need to delay by posting a custom message in an OnChange or OnEnter event handler:

const
  WM_DESELECT = WM_APP + 1;
 
TForm1 = class(TForm)
  <snip>
private
  procedure WMDeSelect(var Msg: TMessage); message WM_DESELECT;
end;
 
procedure TForm1.WMDeSelect(var Msg: TMessage);
begin
  SendMessage(SomeComboBox.Handle, CB_SETEDITSEL, 0, 0);
end;
 
procedure TForm1.SomeComboBoxChange(Sender: TObject);
begin
  PostMessage(Handle, WM_DESELECT, 0, 0);
end;
 
procedure TForm1.SomeComboBoxEnter(Sender: TObject);
begin
  PostMessage(Handle, WM_DESELECT, 0, 0);
end;


(This forum is a real pain to use)
--
C-H
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: How to remove TComboBox selection? [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 12:47 PM   in response to: Carl-Henrik Nil... in response to: Carl-Henrik Nil...
On Sat, 8 Aug 2015 09:36:32 -0700, Carl-Henrik Nilsson <> wrote:

Bo Berglund wrote:
<snip>
Any idea how I could deselct the text in the TNumComboBox in code?

I'm not sure about your scenario or when you want to remove the
selection in the edit child control of the ComboBox,

When the form is shown for the first time after starting the
application some of the TNumComboBox components show their text as
selected (dark blue background). This can be removed manually for
controls that are enabled by setting the cursor in the box with the
mouse. But this is not optimal behaviour, I would rather have these
controls show unselected text all the time.
And any such control which is not enabled cannot be fixed manually
because the cursor cannot be set on these.

but normally sending a CB_SETEDITSEL message to the ComboBox is the way to do it:
SendMessage(SomeComboBox.Handle, CB_SETEDITSEL, 0, 0);

I don't know how to do this...
I tried adding this to the button event function shown below:
  SendMessage(cbxDepthFactor.Handle, CB_SETEDITSEL, 0, 0);

But this would not compile because:
[dcc32 Error] FormSettings.pas(301): E2003 Undeclared identifier:
'CB_SETEDITSEL'

Normally setting Enabled to False will also remove the selection.
Well, most of the problem controls are set enabled=false in the
designer. They are only enabled in certain cases of other settings.


If sending a CB_SETEDITSEL message doesn't work in your scenario, then you could instead try toggling
the Enabled state, possibly a couple of times if needed.

For example, if the ComboBox is Enabled:
SomeComboBox.Enabled := False; //Removes the selection
SomeComboBox.Enabled := True; //Enabled and still no selection

The toggling isn't noticeable.

I tested your suggestion by adding a button on the form and putting
this on the buttonclick event:
procedure TfrmSettings.Button1Click(Sender: TObject);
var
  State1, State2: boolean;
begin
  State1 := cbxDepthFactor.Enabled;
  State2 := cbxForwCGIter.Enabled;
  cbxDepthFactor.Enabled := true;
  cbxForwCGIter.Enabled := true;
  Sleep(5);
  cbxDepthFactor.Enabled := State1;
  cbxForwCGIter.Enabled := State2;
end;

But nothing at all happens when I click the button...

Remove the selection wherever you feel it's needed - in an OnChange or OnEnter event handler, for instance.
???
My problem is that I don't know how to remove the selection in the
first place....
The sendmessage did not work because the compiler did not like it...

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572
Carl-Henrik Nil...

Posts: 53
Registered: 3/26/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 2:33 PM   in response to: Bo Berglund in response to: Bo Berglund
Bo Berglund wrote:
My problem is that I don't know how to remove the selection in the
first place....
The sendmessage did not work because the compiler did not like it...

CB_SETEDITSEL is declared in Winapi.Messages, so add it to uses.

Try posting a WM_DESELECT custom message in a ComboBox OnChange or OnEnter event handler.
Try also posting such a message in an OnShow event handler for the form:

const
  WM_DESELECT = WM_APP + 1;
 
TForm1 = class(TForm)
  <snip>
private
  procedure WMDeSelect(var Msg: TMessage); message WM_DESELECT;
end;
 
 
procedure TForm1.WMDeSelect(var Msg: TMessage);
var
  L: Integer;
begin
  L := Length(SomeComboBox.Text);
  SendMessage(SomeComboBox.Handle, CB_SETEDITSEL, 0, MakeLParam(L, L));
end;
 
procedure TForm1.SomeComboBoxChange(Sender: TObject);
begin
  PostMessage(Handle, WM_DESELECT, 0, 0);
end;
 
procedure TForm1.SomeComboBoxEnter(Sender: TObject);
begin
  PostMessage(Handle, WM_DESELECT, 0, 0);
end;
 
procedure TForm1.FormShow(Sender: TObject);
begin
  PostMessage(Handle, WM_DESELECT, 0, 0);
end;

--
C-H
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 2:51 PM   in response to: Carl-Henrik Nil... in response to: Carl-Henrik Nil...
On Sat, 8 Aug 2015 14:33:15 -0700, Carl-Henrik Nilsson <> wrote:

Bo Berglund wrote:
My problem is that I don't know how to remove the selection in the
first place....
The sendmessage did not work because the compiler did not like it...

CB_SETEDITSEL is declared in Winapi.Messages, so add it to uses.

Thanks,
that uses file fixed the compilation error and now I can use the
button on the form to deselect the text in the combobox. :)

Try posting a WM_DESELECT custom message in a ComboBox OnChange or OnEnter event handler.
Try also posting such a message in an OnShow event handler for the form:

Why do I need to do that? Isn't the Sendmessage solution good enough?
If I put the selection clearing into the OnShow event procedure for
the form then I should be able to get rid of the selections, right?
I'll try and report back here.

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572

Bo Berglund

Posts: 757
Registered: 10/23/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 3:14 PM   in response to: Bo Berglund in response to: Bo Berglund
On Sat, 8 Aug 2015 14:51:44 -0700, Bo Berglund
<bo dot berglund at nospam dot com> wrote:

CB_SETEDITSEL is declared in Winapi.Messages, so add it to uses.

Thanks,
that uses file fixed the compilation error and now I can use the
button on the form to deselect the text in the combobox. :)

If I put the selection clearing into the OnShow event procedure for
the form then I should be able to get rid of the selections, right?
I'll try and report back here.

I have done so now and it seems to work fine. This is how I did it for
these two controles:
procedure TfrmSettings.FormShow(Sender: TObject);
begin
  SendMessage(cbxDepthFactor.Handle, CB_SETEDITSEL, 0, 0);
  SendMessage(cbxForwCGIter.Handle, CB_SETEDITSEL, 0, 0);
end;


Now I would like to have a way to iterate through all TNumComboBox
components and do the same to them all, preferably in some kind of
loop so I don't have to list all the controls and keep track of the
names if new items are added.
Any ideas how that could be done inside the form's onshow event?
Something like:
procedure TfrmSettings.FormShow(Sender: TObject);
var
  NCB: TNumComboBox;
  i: integer;
begin
  for i := 0 to <Number_of_Components> -1 do
  begin
    if Component[i] is TNumComboBox then
       SendMessage(TNumComboBox(Component[i]).Handle, CB_SETEDITSEL,
0, 0);
  end;
end;


Is there some way to iterate through and find all TNumComboBoxes on a
form?

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 3:26 PM   in response to: Bo Berglund in response to: Bo Berglund
On Sat, 8 Aug 2015 15:14:01 -0700, Bo Berglund
<bo dot berglund at nospam dot com> wrote:

Is there some way to iterate through and find all TNumComboBoxes on a
form?

Yes, this works fine for all of the boxes in the form:
procedure TfrmSettings.FormShow(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to ComponentCount -1 do
  begin
    if Components[i] is TNumComboBox then
       SendMessage(TNumComboBox(Components[i]).Handle,
CB_SETEDITSEL,0, 0);
  end;
end;


Thanks again for your suggestions, I think the problem is now solved
(on the main form and the settings form at least)..

---
Bo Berglund
Sweden & Texas
Newsreader: Forte Free Agent 1.92/32.572

Carl-Henrik Nil...

Posts: 53
Registered: 3/26/02
Re: How to remove TComboBox selection?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 8, 2015 3:44 PM   in response to: Bo Berglund in response to: Bo Berglund
Bo Berglund wrote:
On Sat, 8 Aug 2015 14:51:44 -0700, Bo Berglund
<bo dot berglund at nospam dot com> wrote:

CB_SETEDITSEL is declared in Winapi.Messages, so add it to uses.

Thanks,
that uses file fixed the compilation error and now I can use the
button on the form to deselect the text in the combobox. :)

If I put the selection clearing into the OnShow event procedure for
the form then I should be able to get rid of the selections, right?
I'll try and report back here.

I have done so now and it seems to work fine. This is how I did it for
these two controles:
procedure TfrmSettings.FormShow(Sender: TObject);
begin
  SendMessage(cbxDepthFactor.Handle, CB_SETEDITSEL, 0, 0);
  SendMessage(cbxForwCGIter.Handle, CB_SETEDITSEL, 0, 0);
end;

Well, there you go. Posting the WM_DESELECT message was necessary had you used the other event handlers - puts the handling
last in the message queue.

Now I would like to have a way to iterate through all TNumComboBox
components and do the same to them all, preferably in some kind of
loop so I don't have to list all the controls and keep track of the
names if new items are added.
Any ideas how that could be done inside the form's onshow event?
Something like:
procedure TfrmSettings.FormShow(Sender: TObject);
var
  NCB: TNumComboBox;
  i: integer;
begin
  for i := 0 to <Number_of_Components> -1 do
  begin
    if Component[i] is TNumComboBox then
       SendMessage(TNumComboBox(Component[i]).Handle, CB_SETEDITSEL,
0, 0);
  end;
end;


Is there some way to iterate through and find all TNumComboBoxes on a
form?

procedure TfrmSettings.FormShow(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to ComponentCount - 1 do
  begin
    if Components[i] is TNumComboBox then
       SendMessage((Components[i] as TNumComboBox).Handle, CB_SETEDITSEL, 0, 0);
  end;
end;

--
C-H
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02