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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:41:37+00:00 2026-06-08T09:41:37+00:00

In a MVVM Silverlight application the user can enter text in the TextBox and

  • 0

In a MVVM Silverlight application the user can enter text in the TextBox and the ListBox contents changes accordingly.
E.g.: If the user enter “TV” the ListBox will populate all the available Television brands and the user can select a product from the ListBox and ListBox entries; next if he enters “computer” ListBox contents change and populate with ComputerNames.

As soon as the user types something it searches in a dictionary with values matching key.

View:

<TextBox Name="SearchTBox" Text="{Binding SearchStr,UpdateSourceTrigger=PropertyChanged}" />
<ListBox Name="AnalysisLBox" ItemsSource="{Binding DataList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"   
         SelectedItem="{Binding UserSelectedItem,Mode=TwoWay}"                                   
         Width="250" BorderBrush="Transparent" SelectedIndex="{Binding LBoxSelectedIndex,Mode=TwoWay}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding}" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

ViewModel:

SortedDictionary Data()
{
    List<string> tvList = new List<string>() { "Sony", "SamSung", "LG","Sharp" };
    List<string> computerList = new List<string>() { "HP","Dell","Lenovo","Gateway" };
    List<string> cameraList = new List<string>() { "Nikon","Sony","Panasonic" };
    SortedDictionary<string, List<string>> Data = new SortedDictionary<string, List<string>>();
    Data.Add("TV", billingList);
    Data.Add("Computer", salesOutList);
    Data.Add("Camera", customerAllocationList);
}

ObservableCollection<string> dataList = new ObservableCollection<string>();
public ObservableCollection<string> DataList
{
    get { return dataList ; }
    set { dataList = value; NotifyPropertyChanged("DataList"); }
}

int lBoxSelectedIndex;
public int LBoxSelectedIndex
{
    get { return lBoxSelectedIndex; }
    set { lBoxSelectedIndex = value; NotifyPropertyChanged("LBoxSelectedIndex"); }
}

string userSelectedItem;
public string UserSelectedItem
{
    get { return userSelectedItem; }
    set
    {
        userSelectedItem = value;
    dataList.Clear(); 
        LBoxSelectedIndex =-1;
        NotifyPropertyChanged("UserSelectedItem");
    }
 }

As soon as a key matches user typed string (‘TV’) it populates an ObservableCollection<string> dataList with tvList which is bound to the ListBox. The user types Camera, it clears the dataList and adds cameraList. The problem occurs here. The listBox’s selection is not cleared when it clears data and populates with new data. The same item at the previously selected location remain selected.
I tried to set the SelectedIndex to -1 from the UserSelectedItem Property of the ViewModel but it didn’t work.

  • 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-08T09:41:38+00:00Added an answer on June 8, 2026 at 9:41 am

    You can also set userSelectedItem=null in

    ObservableCollection<string> dataList = new ObservableCollection<string>();
    public ObservableCollection<string> DataList
    {
        get { return dataList ; }
        set 
        { 
            dataList = value;
            userSelectedItem=null
            LBoxSelectedIndex = -1;
            NotifyPropertyChanged("DataList"); 
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use MVVM design pattern in WPF and Silverlight Application. Where can i
I have a silverlight mvvm application that loads main view with 2 user controls
I am trying to put all the pieces together for my MVVM Silverlight application
I have a silverlight application (MVVM) with a view that will be used by
I'm coding an MVVM Silverlight application with MVVMLight. I was asking myself what is
I have an MVVM Silverlight 4 application that holds a list of modules (a
I'm using mvvm light to build a Silverlight application. Is there a code snippet
I am creating a Silverlight 4 application with Entity Framework, RIA Services and MVVM-Light
In my Silverlight MVVM application, in the code-behind of a view, I set the
When creating a test project for a Silverlight MVVM application, should I create a

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.