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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:09:52+00:00 2026-05-15T11:09:52+00:00

I have a problem with AutoCompleteBox. I wanted to use it as editable combobox.

  • 0

I have a problem with AutoCompleteBox. I wanted to use it as editable combobox. So I created custom control inheriting from AutoCompletBox and added two dependency properties named as SelectedValue (for binding to DataContext) and SelectedValuePath. When user selects an item, my custom control updates SelectedValue as the following way:

string propertyPath = this.SelectedValuePath;
PropertyInfo propertyInfo = this.SelectedItem.GetType().GetProperty(propertyPath);
object propertyValue = propertyInfo.GetValue(this.SelectedItem, null);
this.SelectedValue = propertyValue;

It works.

Reversely, when underlying datacontext changed, SelectedValue is also changed; so custom control’s SelectedItem also has to change:

if (this.SelectedValue == null)
{
   this.SelectedItem = null; //Here's the problem!!!
}
else
{
   object selectedValue = this.SelectedValue;
   string propertyPath = this.SelectedValuePath;
   if (selectedValue != null && !(string.IsNullOrEmpty(propertyPath)))
   {
      foreach (object item in this.ItemsSource)
      {
         PropertyInfo propertyInfo = item.GetType().GetProperty(propertyPath);
         if (propertyInfo.GetValue(item, null).Equals(selectedValue))
            this.SelectedItem = item;
      }
   }
}

What troubles me is when SelectedValue is null. Even if SelectedItem is set to null, Text property is not cleared, if it was manually edited by user. So SelectedItem = null but AutoCompleteBox displays a text entered manually. Can someone show me right way of resetting AutoCompleteBox.SelectedItem property?

  • 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-15T11:09:53+00:00Added an answer on May 15, 2026 at 11:09 am

    What a coincidence… I was just doing the same thing today. In fact don’t even bother to set SelectedItem = null. You can just set Text = String.Empty and both the text area and the SelectedItem will be cleared.

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

Sidebar

Related Questions

I have problem with sending a object from my webservice. I have created a
I have a problem with the Autocompletebox control which doesn't work in Blend which
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
Have problem while getting data from Memcached on .NET MVC solution. I have this
My problem is happening when I use some attributes in I have the following
I have problem with comparing the value of array elements. e.g. I wanted to
I have problem when creating a file in encoding 'utf-8' and reading it from
I have problem with a fullscreen Flash video. I made a custom Flash video
I have problem on deleting component which is created on runtime. Please help me.
I have problem with $_POST data. Some fields are missing from input form when

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.