Note: This appears to really slowly in M9, although it works well in M8. It probably is better to use teedr's until it can be figured out what is causing the slow speeds.
The following seems to work pretty well. I wrapped the options in a Pane and Framed so the entire row is clickable.
ClearAll[AutoInputField];
SetAttributes[AutoInputField, HoldAllComplete];
AutoInputField /: MakeBoxes[AutoInputField[field_,
list_: {}, displayNum_: Infinity, imageSize_: 100], form_] := Module[{focus = False},
With[{tag = SymbolName@Unique[StringJoin["g", ToString[$SessionID]]] },
CurrentValue[$FrontEndSession, {TaggingRules, tag, "x"}] = "";
field = Dynamic@DynamicModule[{Only = Function[{l, n}, Take[l, Min[Length[l], n]]]},
If[focus ||
Not[CurrentValue[$FrontEndSession, {TaggingRules, tag, "x"}] === ""]
, Column[Map[Function[
EventHandler[Framed[Pane[#,
ImageSize -> Dynamic[(CurrentValue[EvaluationNotebook[], WindowSize][[1]] - 120)]
], FrameMargins -> 0, FrameStyle -> Gray], {
"MouseClicked" :> (
CurrentValue[$FrontEndSession, {TaggingRules, tag, "x"}] = #
)}]],
Select[list, StringMatchQ[#,
CurrentValue[$FrontEndSession, {TaggingRules, tag, "x"}]
~~ ___, IgnoreCase -> True] &]~Only~displayNum]], ""]
];
ToBoxes@EventHandler[
InputField[
Dynamic[
CurrentValue[$FrontEndSession, {TaggingRules, tag, "x"}]
],
String, ContinuousAction -> True, ImageSize -> imageSize], {
"ReturnKeyDown" :> ( (* focusForcedHidden *)
CurrentValue[$FrontEndSession, {TaggingRules, tag, "x"}] =
Append[
Select[list, StringMatchQ[#,
CurrentValue[$FrontEndSession, {TaggingRules, tag, "x"}]
~~ ___, IgnoreCase -> True] &]
, ""][[1]];
focus = False;
),
"MouseEntered" :> ( (* focusForcedDisplay *)
focus = True;
),
"MouseExited" :> ( (* focusForcedDisplay *)
focus = False;
),
"MouseUp" :> ( (* If[x===list[[1]] && Length@list===1] *)
focusForce = True;
),
"KeyDown" :> (
focusForce = False;
)
},
PassEventsDown -> True
]
]];
And the following outputs an AutoCompelete textbox.
(* AutoInputField[d,Map[(ToString[#])&,Table[i^2,{i,10}]]] *)
AutoInputField[d, {"ab", "abc", "100", "1", "16"}]
Pane[d,
ImageSize -> {200, 80},
Scrollbars -> True
]
Column[{InputField[Dynamic@x, String, ContinuousAction -> True], Pane[ Dynamic@Column[Names["System\" ~~ x ~~ "*"]], {220, 300}] }]` You can start with this. – Kuba Jul 13 '13 at 19:38