Is there a way for doing this?
I can draw items as i want, but having items not selectable? Is that
possible?
WBR
Sonnich
const
CB1DisabledIndices = [2, 5];
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if (ComboBox1.ItemIndex in CBDisabledIndices) then
ComboBox1.ItemIndex := -1;
end;
This uses a set for multiple disabling, but if you have only one
then . . .
const
CB1DisabledIndex = 2;
if (ComboBox1.ItemIndex = CBDisabledIndex) then
etc
And when you draw the items if they're disabled then draw them a
different colour.
Alan Lloyd
An alternative to using a separate structure to track item status would be
to use the Items.Objects property:
ComboBox1.Items.Objects [n] := tObject (EnabledValueOfItemN)
or
ComboBox1.Items.AddObject (ItemCaption, tObject (ItemEnabledState))
then
if Boolean (ComboBox1.Items.Object [n]) then // it's enabled
An alternative to setting the ItemIndex to -1 when a disabled item is
selected would be to track the previous value:
In onClick
if not Boolean (ComboBox1.Items.Objects [Combobox1.ItemIndex])
then ComboBox1.ItemIndex := cb1LastIndex;
cbLastIndex := ComboBox1.ItemIndex;
where cbLastIndex is declared in the private section of the form as an
integer.
A good idea, particularly if the disabled items are set dynamically
during program interaction.
OTOH if there are more than 1 disabled items, or if they have to be
set to a default, I think using a set and setting the Objects[] in a
loop is clearer.
DisabledItems = [3, 5, 7];
for i := 0 to MyComboBox.items.Count - 1 do
if i in DisabledItems then . . .
> An alternative to setting the ItemIndex to -1 when a disabled item is
> selected would be to track the previous value:
>
> In onClick
>
> � � if not Boolean (ComboBox1.Items.Objects [Combobox1.ItemIndex])
> � � then ComboBox1.ItemIndex := cb1LastIndex;
> � � cbLastIndex := ComboBox1.ItemIndex;
>
> where cbLastIndex is declared in the private section of the form as an
> integer.
Good technique.
Alan Lloyd