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 3630888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:19:37+00:00 2026-05-19T00:19:37+00:00

Using the following simple text box as an example: <ComboBox IsEditable=True SelectedItem={Binding}> <ComboBoxItem>Angus/ComboBoxItem> <ComboBoxItem>Jane</ComboBoxItem>

  • 0

Using the following simple text box as an example:

<ComboBox IsEditable="True" SelectedItem="{Binding}">
    <ComboBoxItem>Angus/ComboBoxItem>
    <ComboBoxItem>Jane</ComboBoxItem>
    <ComboBoxItem>Steve</ComboBoxItem>
</ComboBox>

I would like to allow the user to find their selection by typing in a name, so I have set IsEditable equal to true. Acceptable values for the property bound to SelectedItem are any one of the options in the list, or no selection (null). The problem is, there is no error indication by default in the event someone types in a name that isn’t in the list.

For example: a user could type “Bob”, causing the SelectedItem property to be null, but not realize that Bob doesn’t exist in the list. Instead I would like to provide a visual indication as soon as the ComboBox’s Text property is not null or empty AND SelectedItem is null, and stop them from typing any more?

My initial thought was a custom validation rule, but I don’t know how to access both the Text and SelectedItem properties of the combobox.

  • 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-05-19T00:19:38+00:00Added an answer on May 19, 2026 at 12:19 am

    As a starter, you might want to let the user see if they are typing in one of the available options.

    1) Search “autocomplete combobox” online.

    2) Check these out:

    http://weblogs.asp.net/okloeten/archive/2007/11/12/5088649.aspx

    http://www.codeproject.com/KB/WPF/WPFCustomComboBox.aspx

    3) Also try this:

        <ComboBox IsEditable="true" TextSearch.TextPath="Content">
            <ComboBoxItem Content="Hello"/>
            <ComboBoxItem Content="World"/>
        </ComboBox>
    

    The above code snippet is a primite way to provide that “visual indication” you’re looking for. If the user types in ‘h’, then ‘hello’ will appear in the input textbox. However, this on its own won’t have a mechanism to stop the user from typing in an illegal character.

    4) This is a more advanced version:

        <ComboBox Name="myComboBox" IsEditable="true" KeyUp="myComboBox_KeyUp">
            <ComboBoxItem Content="Hello"/>
            <ComboBoxItem Content="World"/>
            <ComboBoxItem Content="WPF"/>
            <ComboBoxItem Content="ComboBox"/>
        </ComboBox>
    

    Code-behind:

        private void myComboBox_KeyUp(object sender, KeyEventArgs e)
        {
            // Get the textbox part of the combobox
            TextBox textBox = myComboBox.Template.FindName("PART_EditableTextBox", myComboBox) as TextBox;
    
            // holds the list of combobox items as strings
            List<String> items = new List<String>();
    
            // indicates whether the new character added should be removed
            bool shouldRemove = true;
    
            for (int i = 0; i < myComboBox.Items.Count; i++)
            {
                items.Add(((ComboBoxItem)myComboBox.Items.GetItemAt(i)).Content.ToString());
            }
    
            for (int i = 0; i < items.Count; i++)
            {
                // legal character input
                if(textBox.Text != "" && items.ElementAt(i).StartsWith(textBox.Text))
                {
                    shouldRemove = false;
                    break;
                }
            }
    
            // illegal character input
            if (textBox.Text != "" && shouldRemove)
            {
                textBox.Text = textBox.Text.Remove(textBox.Text.Length - 1);
                textBox.CaretIndex = textBox.Text.Length;
            }
        }
    

    Here, we don’t let the user continue typing in once we detect that no combobox item starts with the text in the textbox. We remove the character added and wait for another character.

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

Sidebar

Related Questions

I am using the following code for making a simple text box an autocomplete
Using the following code: use LWP::Simple; my $url= http://example.com; my $html= get $url; I
I'm following this example for creating a simple Web application using JAX-RS, MongoDB and
I'm using the following simple Go code to allocate a 3D array of size
My problem is a bit more complex than using the following simple JavaScript code:
I'm using MVC 4, EF 4.3 and the MVCScaffolding package. I have following simple
I am using the following function to create a simple accordion. The problem is
I am trying to download a file using simple java class using the following
I am trying to download a file using simple java class using the following
Simple enough question I hope. I am using the following type of code to

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.