Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7870677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:41:12+00:00 2026-06-03T01:41:12+00:00

My combobox returns a set of values from s stored procedure as this private

  • 0

My combobox returns a set of values from s stored procedure as this

private void BindCombo()
{
    DataCombo.FillCombo(ComboDS(2313001), cmbClass, 0);
    DataCombo.FillCombo(DDCombo(5007), cmbGroup, 0);
}

I managed to give a rudimentary auto complete suggestion as IsTextSearchenabled but cannot get a auto suggestion box that i would like.

I have seen loads of examples of autocomplete/suggestive textboxes but none of them seem to suit me.

this code apparently suits me.

but how would i use the auto suggest here

using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace DotNetZen.AutoFilteredComboBox
{
    public class AutoFilteredComboBox : ComboBox
    {
        private int silenceEvents = 0;

    /// <summary>
    /// Creates a new instance of <see cref="AutoFilteredComboBox" />.
    /// </summary>
    public AutoFilteredComboBox()
    {
        DependencyPropertyDescriptor textProperty = DependencyPropertyDescriptor.FromProperty(
            ComboBox.TextProperty, typeof(AutoFilteredComboBox));
        textProperty.AddValueChanged(this, this.OnTextChanged);

        this.RegisterIsCaseSensitiveChangeNotification();
    }

    #region IsCaseSensitive Dependency Property
    /// <summary>
    /// The <see cref="DependencyProperty"/> object of the <see cref="IsCaseSensitive" /> dependency property.
    /// </summary>
    public static readonly DependencyProperty IsCaseSensitiveProperty =
        DependencyProperty.Register("IsCaseSensitive", typeof(bool), typeof(AutoFilteredComboBox), new UIPropertyMetadata(false));

    /// <summary>
    /// Gets or sets the way the combo box treats the case sensitivity of typed text.
    /// </summary>
    /// <value>The way the combo box treats the case sensitivity of typed text.</value>
    [System.ComponentModel.Description("The way the combo box treats the case sensitivity of typed text.")]
    [System.ComponentModel.Category("AutoFiltered ComboBox")]
    [System.ComponentModel.DefaultValue(true)]
    public bool IsCaseSensitive
    {
        [System.Diagnostics.DebuggerStepThrough]
        get
        {
            return (bool)this.GetValue(IsCaseSensitiveProperty);
        }
        [System.Diagnostics.DebuggerStepThrough]
        set
        {
            this.SetValue(IsCaseSensitiveProperty, value);
        }
    }

    protected virtual void OnIsCaseSensitiveChanged(object sender, EventArgs e)
    {
        if (this.IsCaseSensitive)
            this.IsTextSearchEnabled = false;

        this.RefreshFilter();
    }

    private void RegisterIsCaseSensitiveChangeNotification()
    {
        System.ComponentModel.DependencyPropertyDescriptor.FromProperty(IsCaseSensitiveProperty, typeof(AutoFilteredComboBox)).AddValueChanged(
            this, this.OnIsCaseSensitiveChanged);
    }
    #endregion

    #region DropDownOnFocus Dependency Property
    /// <summary>
    /// The <see cref="DependencyProperty"/> object of the <see cref="DropDownOnFocus" /> dependency property.
    /// </summary>
    public static readonly DependencyProperty DropDownOnFocusProperty =
        DependencyProperty.Register("DropDownOnFocus", typeof(bool), typeof(AutoFilteredComboBox), new UIPropertyMetadata(true));

    /// <summary>
    /// Gets or sets the way the combo box behaves when it receives focus.
    /// </summary>
    /// <value>The way the combo box behaves when it receives focus.</value>
    [System.ComponentModel.Description("The way the combo box behaves when it receives focus.")]
    [System.ComponentModel.Category("AutoFiltered ComboBox")]
    [System.ComponentModel.DefaultValue(true)]
    public bool DropDownOnFocus
    {
        [System.Diagnostics.DebuggerStepThrough]
        get
        {
            return (bool)this.GetValue(DropDownOnFocusProperty);
        }
        [System.Diagnostics.DebuggerStepThrough]
        set
        {
            this.SetValue(DropDownOnFocusProperty, value);
        }
    }
    #endregion

    #region | Handle selection |
    /// <summary>
    /// Called when <see cref="ComboBox.ApplyTemplate()"/> is called.
    /// </summary>
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        this.EditableTextBox.SelectionChanged += this.EditableTextBox_SelectionChanged;
    }

    /// <summary>
    /// Gets the text box in charge of the editable portion of the combo box.
    /// </summary>
    protected TextBox EditableTextBox
    {
        get
        {
            return ((TextBox)base.GetTemplateChild("PART_EditableTextBox"));
        }
    }

    private int start = 0, length = 0;

    private void EditableTextBox_SelectionChanged(object sender, RoutedEventArgs e)
    {
        if (this.silenceEvents == 0)
        {
            this.start = ((TextBox)(e.OriginalSource)).SelectionStart;
            this.length = ((TextBox)(e.OriginalSource)).SelectionLength;

            this.RefreshFilter();
        }
    }
    #endregion

    #region | Handle focus |
    /// <summary>
    /// Invoked whenever an unhandled <see cref="UIElement.GotFocus" /> event
    /// reaches this element in its route.
    /// </summary>
    /// <param name="e">The <see cref="RoutedEventArgs" /> that contains the event data.</param>
    protected override void OnGotFocus(RoutedEventArgs e)
    {
        base.OnGotFocus(e);

        if (this.ItemsSource != null && this.DropDownOnFocus)
        {
            this.IsDropDownOpen = true;
        }
    }
    #endregion

    #region | Handle filtering |
    private void RefreshFilter()
    {
        if (this.ItemsSource != null)
        {
            ICollectionView view = CollectionViewSource.GetDefaultView(this.ItemsSource);
            view.Refresh();
            this.IsDropDownOpen = true;
        }
    }

    private bool FilterPredicate(object value)
    {
        // We don't like nulls.
        if (value == null)
            return false;

        // If there is no text, there's no reason to filter.
        if (this.Text.Length == 0)
            return true;

        string prefix = this.Text;

        // If the end of the text is selected, do not mind it.
        if (this.length > 0 && this.start + this.length == this.Text.Length)
        {
            prefix = prefix.Substring(0, this.start);
        }

        return value.ToString()
            .StartsWith(prefix, !this.IsCaseSensitive, CultureInfo.CurrentCulture);
    }
    #endregion

    /// <summary>
    /// Called when the source of an item in a selector changes.
    /// </summary>
    /// <param name="oldValue">Old value of the source.</param>
    /// <param name="newValue">New value of the source.</param>
    protected override void OnItemsSourceChanged(System.Collections.IEnumerable oldValue, System.Collections.IEnumerable newValue)
    {
        if (newValue != null)
        {
            ICollectionView view = CollectionViewSource.GetDefaultView(newValue);
            view.Filter += this.FilterPredicate;
        }

        if (oldValue != null)
        {
            ICollectionView view = CollectionViewSource.GetDefaultView(oldValue);
            view.Filter -= this.FilterPredicate;
        }

        base.OnItemsSourceChanged(oldValue, newValue);
    }

    private void OnTextChanged(object sender, EventArgs e)
    {
        if (!this.IsTextSearchEnabled && this.silenceEvents == 0)
        {
            this.RefreshFilter();

            // Manually simulate the automatic selection that would have been
            // available if the IsTextSearchEnabled dependency property was set.
            if (this.Text.Length > 0)
            {
                foreach (object item in CollectionViewSource.GetDefaultView(this.ItemsSource))
                {
                    int text = item.ToString().Length, prefix = this.Text.Length;
                    this.SelectedItem = item;

                    this.silenceEvents++;
                    this.EditableTextBox.Text = item.ToString();
                    this.EditableTextBox.Select(prefix, text - prefix);
                    this.silenceEvents--;
                    break;
                }
            }
        }
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:41:14+00:00Added an answer on June 3, 2026 at 1:41 am

    I have found a super simple workaround to my problem.

    i created a preview text input event of the combobox.

    then i just wrote

    Combobox.IsDropDownOpen = true
    

    may not the most elegant but works in my case

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I filled up a combobox with the values from an Enum. Now a combobox
The Following code returns a stored procedure with a hard value coded. I need
I have a combobox in a WPF Window, it is filled with usernames from
I want to display a child window that contains a combobox with several values
I have a combobox inside of my WPF DataGrid. It is created like this:
I have a ComboBox that it looks like this: <ComboBox ItemsSource={Binding JobList} SelectedValue={Binding Job,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}
I would like to create a custom WPF control that inherits from comboBox. So
I was trying to create a custom combobox that inherited from ComboBox, but I've
I have this stupid problem. I bind from view model class property type of
I am learning Fluent NHibernate and this issue arose from that project. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.