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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:11:29+00:00 2026-06-16T20:11:29+00:00

I have a problem with a list, which is bound to a ComboBox .

  • 0

I have a problem with a list, which is bound to a ComboBox.

The List:

private List<string> _CourseList = new List<string>();
public List<string> CourseList
        {
            get { return _CourseList; }
            set
            {
                _CourseList = value;
                OnPropertyChanged("CourseList");
            }
        }

XAML code of the ComboBox:

<ComboBox x:Name="cbxCourse" Height="23" MinWidth="100" Margin="5,1,5,1" VerticalAlignment="Top" ItemsSource="{Binding Path=CourseList}" IsEnabled="{Binding Path=CanExport}" SelectedIndex="{Binding Path=CourseListSelectedIndex}" SelectedItem="{Binding Path=CourseListSelectedItem}" SelectionChanged="cbxCourse_SelectionChanged"/>

Now i fill the List from another thread:

void Database_LoadCompleted(object sender, SqliteLoadCompletedEventArgs e)
{
    foreach (DataTable Table in DataSetDict[CampagneList[0]].Tables)
    {
        CourseList.Add(Table.TableName);
    }
}

Everything looks good, and the ComboBox changed its items.
When I try to update the ComboBox (CourseList) in the MainThread with:

    private void cbxCampagne_SelectionChanged(object sender, EventArgs e)
    {
        if (cbxCampagne.SelectedItem != null)
        {
            CourseList.Clear();
            foreach (DataTable Table in DataSetDict[CampagneList[_CampagneListSelectedIndex]].Tables)
            {
                CourseList.Add(Table.TableName);
            }
    }

all Elements of CourseList changed (I can see it in a Textbox) but in the ComboxBox nothing happens.

Any ideas?

  • 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-16T20:11:33+00:00Added an answer on June 16, 2026 at 8:11 pm

    Try changing CourseList an ObervableCollection<T>

    http://msdn.microsoft.com/en-us/library/ms668604.aspx

    The Binding only notifies the UI when CourseList is set (when the list is assigned) and not when its contents change.

    Some Code from Invoke event on MainThread from worker thread

    This demonstrates that the List<> will not change once assigned and the ObservableList<> will change.

    ViewModel

    //Viewmodel
    public class WindowViewModel : INotifyPropertyChanged
    {
        private volatile bool _canWork;
        private List<string> _items;
        private ObservableCollection<string> _obervableItems;
    
        public WindowViewModel()
        {
            //Queue some tasks for adding and modifying the list
            ThreadPool.QueueUserWorkItem(AddItems);
            ThreadPool.QueueUserWorkItem(ModifyItems);
    
            //Create a background worker to do some work and then we can bind the output to
            //our ObservableList
            var obervableWorker = new BackgroundWorker();
            obervableWorker.DoWork += ObervableWorkerOnDoWork;
            obervableWorker.RunWorkerCompleted += ObervableWorkerOnRunWorkerCompleted;
    
            obervableWorker.RunWorkerAsync();
        }
    
        private void ObervableWorkerOnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs runWorkerCompletedEventArgs)
        {
            var items = ObservableItems as ObservableCollection<string>;
    
            var workerItems = runWorkerCompletedEventArgs.Result as List<string>;
    
            foreach (var workerItem in workerItems)
            {
                items.Add(workerItem);
            }
    
            for (int i = 50; i < 60; i++)
            {
                var item = items.First(x => x == i.ToString());
                items.Remove(item);
            }
        }
    
        private void ObervableWorkerOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs)
        {
            Thread.Sleep(100);
            int count = 0;
            var items = new List<string>();
            while (100 > count++)
            {
                items.Add(count.ToString());
            }
    
            doWorkEventArgs.Result = items;
        }
    
        private void ModifyItems(object state)
        {
            while (!_canWork)
            {
                Thread.Sleep(100);
            }
            var items = Items as List<string>;
            for (int i = 50; i < 60; i++)
            {
                items.RemoveAt(i);
            }
        }
    
        private void AddItems(object state)
        {
            Thread.Sleep(100);
            int count = 0;
            var items = Items as List<string>;
            while (100 > count++)
            {
                items.Add(count.ToString());
            }
            _canWork = true;
        }
    
        public IEnumerable<string> Items
        {
            get { return _items ?? (_items = new List<string>()); }
            set { _items = new List<string>(value);
                OnPropertyChanged();
            }
        }
    
        public IEnumerable<string> ObservableItems
        {
            get { return _obervableItems ?? (_obervableItems = new ObservableCollection<string>()); }
            set { _obervableItems = new ObservableCollection<string>(value); OnPropertyChanged();}
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    

    Window

    //Window.Xaml
    <Window x:Class="ComboBox.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:comboBox="clr-namespace:ComboBox"
            Title="MainWindow" Height="350" Width="525">
        <Window.DataContext><comboBox:WindowViewModel /></Window.DataContext>
        <Grid>
            <ComboBox Width="200" Height="22" ItemsSource="{Binding Items}"></ComboBox>
            <ComboBox Margin="0,44,0,0" Width="200" Height="22" ItemsSource="{Binding ObservableItems}"></ComboBox>
        </Grid>
    </Window>
    

    This can be easily modified to use the Dispatcher Invoke: Change WPF controls from a non-main thread using Dispatcher.Invoke

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

Sidebar

Related Questions

My problem is: I have a GridView, which is bound to list of declared
I have a small problem. I have a set of ComboBox's that are bound
if have the following problem: I have a List which i am going through
I have a problem with following script. It generates a list of places which
I have a page which list comments of users. My problem is that I
Here is my problem : I have a list of messages which I can
Here's my problem: I have do create a menu/list of actions (which would be
I have web-service which give list of property at a particular area My problem
Example of the problem If I have a list of valid option strings which
I have a datagridview with a bound combobox column which contains decimal value. There

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.