diff --git a/SAM.Picker/GamePicker.Designer.cs b/SAM.Picker/GamePicker.Designer.cs index 0346a70..875e5f3 100644 --- a/SAM.Picker/GamePicker.Designer.cs +++ b/SAM.Picker/GamePicker.Designer.cs @@ -181,6 +181,7 @@ this._GameListView.ItemActivate += new System.EventHandler(this.OnActivateGame); this._GameListView.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.OnSelectGame); this._GameListView.RetrieveVirtualItem += new System.Windows.Forms.RetrieveVirtualItemEventHandler(this.OnGameListViewRetrieveVirtualItem); + this._GameListView.SearchForVirtualItem += new System.Windows.Forms.SearchForVirtualItemEventHandler(this.OnGameListViewSearchForVirtualItem); // // _PickerStatusStrip // diff --git a/SAM.Picker/GamePicker.cs b/SAM.Picker/GamePicker.cs index 4741e64..9adbaa8 100644 --- a/SAM.Picker/GamePicker.cs +++ b/SAM.Picker/GamePicker.cs @@ -174,6 +174,55 @@ namespace SAM.Picker }; } + private void OnGameListViewSearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e) + { + if (e.Direction != SearchDirectionHint.Down || e.IsTextSearch == false) + { + return; + } + + var count = this._FilteredGames.Count; + if (count < 2) + { + return; + } + + var text = e.Text.ToLowerInvariant(); + int startIndex = e.StartIndex; + + Predicate predicate; + /*if (e.IsPrefixSearch == true)*/ + { + predicate = gi => gi.Name != null && gi.Name.ToLowerInvariant().StartsWith(e.Text); + } + /*else + { + predicate = gi => gi.Name != null && gi.Name.ToLowerInvariant() == e.Text; + }*/ + + int index; + if (e.StartIndex >= count) + { + // starting from the last item in the list + index = this._FilteredGames.FindIndex(0, startIndex - 1, predicate); + } + else if (startIndex <= 0) + { + // starting from the first item in the list + index = this._FilteredGames.FindIndex(0, count, predicate); + } + else + { + index = this._FilteredGames.FindIndex(startIndex, count - startIndex, predicate); + if (index < 0) + { + index = this._FilteredGames.FindIndex(0, startIndex - 1, predicate); + } + } + + e.Index = index < 0 ? -1 : index; + } + private void DoDownloadLogo(object sender, DoWorkEventArgs e) { var info = (GameInfo)e.Argument;