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

  • Home
  • SEARCH
  • 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 4086038
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:40:09+00:00 2026-05-20T18:40:09+00:00

Trying to fill the listbox programatically I have written the following code: protected override

  • 0

Trying to fill the listbox programatically I have written the following code:

protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            TestDBContext context = new TestDBContext();
            context.Load(context.GetTaskQuery());

        var taskList = GetTasks();
        foreach (var t in taskList)
        {
            ListBoxTaskItems.Items.Add(t);

        }
    }

    private List<TaskItem> GetTasks()
    {
        var tasks = from t in context.Tasks
                    select new TaskItem(t);
        return tasks.ToList();
    }

The problem is that the code above alway returns an empty ListBox. Does anyone know how to modify the existing code or another way to programatically fill the listbox with the data entries?

Edit #1: While debugging I’ve noticed that GetTasks() method is executed before context.GetTaskQuery() and I gues this is the reason for an empty ListBox. Nevertheless I don’t know how to fix the code in order to populate the ListBox.

Thank you!

  • 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-20T18:40:10+00:00Added an answer on May 20, 2026 at 6:40 pm

    Somebody posted another solution, then for whatever reason deleted it, but that might work better. I just tried it in some code I’m working on and found it was faster:

    Binding bind = new Binding();
    
    bind.Source = GetTasks();
    
    ListBoxTaskItems.SetBinding(ListBox.ItemsSourceProperty, bind);
    

    (Substitute this for the foreach statement).

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

Sidebar

Related Questions

I have been trying to do a fill using the open source Srecord Program.
I'm trying to use a Thread in a simple winform. I have a ListBox
I am trying to fill a form in a php application from a C#
Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
I'm trying to make a standard WPF listbox be dynamically filled, and for each
I'm trying the content of a shopping cart in an ItemsControl(ListBox) . To do
I am trying to bulk export out of a sql table, the code works
We are trying to fill our Flex 3 applications background with an image pattern
I'm was trying to fill in a description field when a drop-down was selected.

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.