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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:47:08+00:00 2026-06-10T21:47:08+00:00

I was preparing a sample code in which text in ListBox is automatically selected

  • 0

I was preparing a sample code in which text in ListBox is automatically selected as user makes text entry in TextBox. So far I have achieved the result, but there is no case insensitive matching. Here is code.

XAML

<StackPanel>
    <TextBox Name="txt" />
    <ListBox ItemsSource="{Binding Employees}" DisplayMemberPath="Name" SelectedValuePath="Name" 
             Height="100" SelectedValue="{Binding Text, ElementName=txt}" SelectedItem="{Binding SelectedEmployee}"/>
    <Button Content="OK" Command="{Binding SaveCommand}" />
</StackPanel>

I am binding this XAML with following ViewModel.

ViewModel

public class CheckViewModel : ViewModel.ViewModelBase
{
    IList<Employee> employees;

    Employee _selectedEmployee;

    public CheckViewModel()
    {
        employees = new List<Employee>() { 
            new Employee(1, "Morgan"), 
            new Employee(2, "Ashwin"), 
            new Employee(3, "Shekhar"),
            new Employee(5, "Jack"),
            new Employee(5, "Jill")
        };
    }

    public IList<Employee> Employees
    {
        get
        { return employees; }
    }

    public Employee SelectedEmployee
    {
        get
        { return _selectedEmployee; }
        set
        {
            if (_selectedEmployee != value)
            {
                _selectedEmployee = value;
                this.OnPropertyChanged("SelectedEmployee");
            }
        }
    }

    ICommand _saveCommand;
    public ICommand SaveCommand
    {
        get
        {
            if (_saveCommand == null)
            {
                _saveCommand = new ViewModel.RelayCommand((p) =>
                {
                    if(this._selectedEmployee != null)
                        MessageBox.Show(this._selectedEmployee.Name);
                    else
                        MessageBox.Show("None Selected");
                },
                (p) =>
                {
                    return this._selectedEmployee != null;
                });
            }
            return _saveCommand;
        }
    }
}

public class Employee
{
    public Employee(int id, string name)
    {
        this.Name = name;
        this.Id = id;
    }
    public string Name { get; set; }
    public int Id { get; set; }
}

So when I type “Jack” in TextBox, the selection duly occurs. But when I change the case – “jack” – the selection does not occur and SelectedEmployee becomes null. Certainly, the comparison is case sensitive, but how can I change this behaviour?

Could you please guide me how to make the comparison case insensitive?

  • 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-10T21:47:09+00:00Added an answer on June 10, 2026 at 9:47 pm

    You can bind your textbox to property in ViewModel as follows:

        <TextBox Name="txt" Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"/>
    

    ViewModel:

        public string SearchText
        {
            get { return _searchText; }
            set
            {
                _searchText = value;
                // provide your own search through your collection and set SelectedEmployee
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm preparing for an exam and after going over some sample exercises (which have
I am preparing an Excel sheet in which I have to maintain the version
I am preparing a screen in which user will input an anonymous block (declare
I preparing a images gallery,I want to ZoomIn and ZoomOut of images which are
In preparing to a OOP exam, I enjoyed seeing g++ compile the following code
I am preparing a simple dictionary project and I have prepared it to search
I'm preparing to the SQL Server exam (70-431). I have the book from Sybex
I have a modest-sized table, 277k records at the moment, which I am trying
I found a snippet similar to this in some (C++) code I'm preparing for
I am new to hibernate world and preparing a demo sample. I tried with

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.