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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:00:17+00:00 2026-06-02T06:00:17+00:00

I made a custom control, consisting of a few grids, stackpanels and textblocks. Which

  • 0

I made a custom control, consisting of a few grids, stackpanels and textblocks. Which i want to use as a ListBox Item. I am using it to display more than one line of information in each item of the list, like it’s shown in the image. The control’s name is ItemDetail.

Custom control for listbox

To fill the list, i click on each of the buttons above, which make a SQL query (the query can sometimes take about 5 seconds, and makes it more than noticeable that the UI has frozen).

To fix that, I’m using a BackgroundWorker for the SQL query, and reporting the progress everytime a resulting row from the query is returned.

private void Departamento_Click(object sender, MouseButtonEventArgs e)
    {
        Elementos_Lista.Items.Clear();
        BackgroundWorker _worker = new BackgroundWorker();
        _worker.WorkerReportsProgress = true;
        _worker.ProgressChanged += new ProgressChangedEventHandler(_worker_ProgressChanged);

        _worker.DoWork += delegate(object s, DoWorkEventArgs args)
        {
           //SQL query
           reglas.Consulta("cerrado='0' and grupo='3' order by fecha desc");   

            foreach (DataRow dr in reglas.Entidad.tabla.Rows)
            {
                _worker.ReportProgress(0, dr);
            }

        };
        _worker.RunWorkerAsync();
    }

And I’m using the BackgroundWorker’s IsProgressChanged event to add the data to an instance of ItemDetail, and then adding it to the ListBox.

 void _worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        ItemDetail item = new ItemDetail((DataRow)e.UserState);
        Elementos_Lista.Items.Add(item);
    }

This way, the operation takes a lot less time, but it still freezes, and it’s due to the UI refresh that has to be done after each row of the query is returned. The BackgroundWorker doesn’t let me add the data to the ItemDetail control in a separate thread, because it’s no the UI thread.

Is there a way I can speed up the process of rendering a lot of controls at once or add them in smaller batches to the list, so the UI doesn’t seem completely unresponsive until it’s done filling the list?.

  • 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-02T06:00:19+00:00Added an answer on June 2, 2026 at 6:00 am

    Just add the data to an ObservableCollection which should be bound to your list control and let it generate the controls via data templates, if you have virtualization unnecessary controls (the ones scrolled out of view) will not be created right away which should make the operation faster.

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

Sidebar

Related Questions

I made a custom control called SmartTabItem , currently just the default implementation: using
I've made a custom control, it's a FlowLayoutPanel, into which I put a bunch
I have made a custom control which consists of a richtextbox and a picture
I have made a custom control for windows phone 7. If I use this
I have made one custom user control (search text box), which basically consists of
I am using a custom calendar control made by someone else (under the GNU-GPL,
I've made a custom control to display a pie chart representing the completion of
I have a custom made ASP control which is based on a select (drop
I made a custom control that is basically a multiline TextBox that allows input,
Made a custom obj called Item with some string fields and one float. .h

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.