Here a new derived component, the TnxListComboBox. It's a TNxCombox that accepts items in the name=value format used in for example ini files. It only displays names but you can retrieve the selected name and value with two new properties 'itemname' and itemvalue'. It functions like a lookup or translating combobox.
Note it only functions properly with the dsDropDownList style (as there is no way to enter the value parytin
Modifications:
added to TNXEdit.pas's interface section:
private
function GetItemName: string;
function GetItemValue: string;
protected
procedure BeforeDrop(var APoint: TPoint); override;
procedure SetItemIndex(const Value: Integer); override;
public
published
property DropDownColor;
property DropDownCount;
property HighlightTextColor;
property Images;
property ItemHeight;
property ItemIndex;
property ItemName: string read GetItemName;
property Items;
property SelectionColor;
property ItemValue: string read GetItemValue;
end;
added to TNXEdit.pas's implementation section:
procedure TNxListComboBox.BeforeDrop(var APoint: TPoint);
var
i : Integer;
begin
with FPopupControl as TNxPopupList do
begin
DropDownColor := Self.DropDownColor;
HighlightTextColor := Self.HighlightTextColor;
if Assigned(Items) then
Items.Free;
Items := TStringList.Create;
for i := 0 to Pred(Self.Items.Count) do
Items.Add(Self.Items.Names[i]);
Images := Self.Images;
ItemHeight := Self.ItemHeight;
ShowImages := Images <> nil;
SelectionColor := Self.SelectionColor;
Width := Self.Width;
if Items.Count <= Self.DropDownCount then
ClientHeight := Items.Count * Self.ItemHeight
else
ClientHeight := Self.DropDownCount * Self.ItemHeight;
end;
end;
function TNxListComboBox.GetItemName: string;
begin
if (ItemIndex <> -1) then
Result := Self.Items.Names[ItemIndex]
else
Result := '';
end;
function TNxListComboBox.GetItemValue: string;
begin
if (ItemIndex <> -1) then
Result := Self.Items.ValueFromIndex[ItemIndex]
else
Result := '';
end;
procedure TNxListComboBox.SetItemIndex(const Value: Integer);
begin
FItemIndex := Value;
TNxPopupList(FPopupControl).ItemIndex := FItemIndex;
if (Items.Count > 0) and InRange(FItemIndex, 0, Items.Count - 1) then
begin
Text := Items.Names[FItemIndex];
end;
end;
and finally a small modification to TNxCombobox SetItemIndex (made it virtual):