I am using TTMSFNCComboBox in a multiplattform app. When the combo box is dropped down, the user can walk through the list of items in the dropped down list by pressing cursor keys on the keyboard.
Is there a way to see which item is the active one in the dropped down listbox and when that changes (when the user uses csr-up or csr-down)?
Sure, it is highlighted, and meanwhile I discovered the items are displayed in a TTMSFNCTreeView Subcomponent which is accessable through the PopUp field.
More specifically my question was about how to get notified when the user uses the cursor keys to walk / scroll through the items / nodes. (I was not complaining about a bug - sorry for my bad description)
Depending on your TTMSFNCComboBox.Style setting you can assign the OnKeyDown events for either the TTMSFNCTreeView or the TEdit control.
csDropDown: In this case the TEdit is always in focus with keyboard navigation so key down events are processed from this control. You can assign your own OnKeyDown event via TTMSFNCComboBox.Edit, but you'll need to save the previous OnKeyDown event and call it from your implementation to not break functionality:
procedure TForm1.FormCreate(Sender: TObject);
begin
FPrevOnKeyDow:= TMSFNCComboBox1.Edit.OnKeyDown;
TMSFNCComboBox1.Edit.OnKeyDown := EKeyDown;
end;
procedure TForm1.EKeyDown(Sender: TObject; var Key: Word; var KeyChar: WideChar; Shift: TShiftState);
begin
FPrevOnKeyDow(Sender, Key, KeyChar, Shift);
Log.d('Key is pressed');
end;
csDropDownList: This is more simple, just use the OnKeyDown event of the TTMSFNCTreeView. We don't utilize this event in TTMSFNCComboBox so there won't be any conflicts.
procedure TmyForm.MyComboBoxPopup(Sender: TObject);
begin
// set OnAfterSelectNode EventHandler in Treeview of MyComboBox
(MyComboBox.Popup.ContentControl.Controls[0] as TTMSFNCTreeView)
.OnAfterSelectNode := AfterSelectNode;
DoSomething(MyComboBox.ItemIndex);
end;
procedure TmyForm.MyComboBoxClosePopup(Sender: TObject);
begin
// reset EventHandler
(MyComboBox.Popup.ContentControl.Controls[0] as TTMSFNCTreeView)
.OnAfterSelectNode := nil;
DoSomething(MyComboBox.ItemIndex);
end;
procedure TmyForm.AfterSelectNode(Sender: TObject;
aNode: TTMSFNCTreeViewVirtualNode);
begin
// Node has been selected by user in popped up TreeView
// (e.g. with cursor keys)
DoSomething(aNode.Index)
end;