/// <summary> /// Handle the SearchForVirtualList event, which is called when the user types into a virtual list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void HandleSearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e) { // The event has e.IsPrefixSearch, but as far as I can tell, this is always false (maybe that's different under Vista) // So we ignore IsPrefixSearch and IsTextSearch and always to a case insensitve prefix match. // We can't do anything if we don't have a data source if (this.DataSource == null) return; // Where should we start searching? If the last row is focused, the SearchForVirtualItemEvent starts searching // from the next row, which is actually an invalidate index -- so we make sure we never go past the last object. int start = Math.Min(e.StartIndex, this.DataSource.GetObjectCount() - 1); // Give the world a chance to fiddle with or completely avoid the searching process BeforeSearchingEventArgs args = new BeforeSearchingEventArgs(e.Text, start); this.OnBeforeSearching(args); if (args.Canceled) return; // Do the search int i = this.FindMatchingRow(args.StringToFind, args.StartSearchFrom, e.Direction); // Tell the world that a search has occurred AfterSearchingEventArgs args2 = new AfterSearchingEventArgs(args.StringToFind, i); this.OnAfterSearching(args2); // If we found a match, tell the event if (i != -1) e.Index = i; }
/// <summary> /// /// </summary> /// <param name="e"></param> protected virtual void OnBeforeSearching(BeforeSearchingEventArgs e) { if (this.BeforeSearching != null) this.BeforeSearching(this, e); }