/// <summary> /// Raises the <see cref="E:AfterSearching"/> event. /// </summary> /// <param name="e">The <see cref="AfterSearchingEventArgs"/> instance containing the event data.</param> protected virtual void OnAfterSearching(AfterSearchingEventArgs e) { if (this.AfterSearching != null) { this.AfterSearching(this, e); } }
/// <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 (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, DataSource.GetObjectCount() - 1); // Give the world a chance to fiddle with or completely avoid the searching process var args = new BeforeSearchingEventArgs(e.Text, start); OnBeforeSearching(args); if (args.Canceled) { return; } // Do the search int i = FindMatchingRow(args.StringToFind, args.StartSearchFrom, e.Direction); // Tell the world that a search has occurred var args2 = new AfterSearchingEventArgs(args.StringToFind, i); OnAfterSearching(args2); // If we found a match, tell the event if (i != -1) { e.Index = i; } }