How can I show correctly a progressbar and a label (that show the percentige) for filling multiple datasets?

Hi All,

I need to update a dataGridView that has master-detail part, I use this control for filling the grid and it childs (I use 4 datasets).

Question: How can I add correctly a thread or more that will add to the grid these datasets and show the correct percentage and the UI remain usable?
 
Please provide me some code.

Thanks advanced,
Steve

Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace MasterDetail
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        MasterControl masterDetail;

        private void frmMain_Load(object sender, EventArgs e)
        {
            //label1.Text = DateTime.Now.ToString();
            clearFields();
            loadData();
            //label2.Text = DateTime.Now.ToString();
        }
        void clearFields()
        {
            panelView.Controls.Clear();
            masterDetail = null;
            Refresh();
            masterDetail = new MasterControl(nwindDataSet);
            panelView.Controls.Add(masterDetail);
        }

        internal delegate void SetDataSourceDelegate();
        private void setDataSource()
        {
            if (this.masterDetail.InvokeRequired)
            {
                this.masterDetail.BeginInvoke(new SetDataSourceDelegate(setDataSource));
            }
            else
            {
                createMasterDetailView();
            }
        }
        void loadData()
        {
            System.Threading.Thread thread =
                       new System.Threading.Thread(new System.Threading.ThreadStart(delegate() { loadDataThread(); }));
            thread.Start();
        }
        void loadDataThread() 
        {
            
            orderReportsTableAdapter.Fill(nwindDataSet.OrderReports);
            invoicesTableAdapter.Fill(nwindDataSet.Invoices);
            employeesTableAdapter.Fill(nwindDataSet.Employees);
            customersTableAdapter.Fill(nwindDataSet.Customers);

            setDataSource();

        }

        void createMasterDetailView() 
        {

            masterDetail.setParentSource(nwindDataSet.Customers.TableName, "CustomerID");
            masterDetail.childView.Add(nwindDataSet.OrderReports.TableName, "Orders");
            masterDetail.childView.Add(nwindDataSet.Invoices.TableName, "Invoices");
            masterDetail.childView.Add(nwindDataSet.Employees.TableName, "Employees");

            typeof(DataGridView).InvokeMember("DoubleBuffered", System.Reflection.BindingFlags.NonPublic |
  System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty, null,
  masterDetail, new object[] { true });

            foreach (DataGridView dvg in masterDetail.childView.childGrid)
            {
                typeof(DataGridView).InvokeMember("DoubleBuffered", System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.SetProperty, null,
dvg, new object[] { true });
            }
            masterDetail.childView.childGrid[2].RowTemplate.Height = 100;
        }
        private void btnLoad_Click(object sender, EventArgs e)
        {

        }

        private void btnLoad_Click_1(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

Open in new window

LVL 13
Molnar IstvánHelpDesk / ProgrammerAsked:
Who is Participating?
 
Éric MoreauSenior .Net ConsultantCommented:
You can't. No information are returned from the database to the client while loading
0
 
Molnar IstvánHelpDesk / ProgrammerAuthor Commented:
If I do for each ,2x selects: one for counting the total rows and one for loading the entire data?
I'm thinking to count the rows before fill.

The problem is that in every table I have 10000+ rows and the app sometimes it freezes, becomes unresponsive.

Thanks advanced
0
 
Éric MoreauSenior .Net ConsultantCommented:
but I never saw a case were it was required to show 10000+ rows in datagrids. No users will ever work with that amount of data without filtering/refreshing the data at some point!
0
 
Éric MoreauSenior .Net ConsultantCommented:
it is the answer even if it is no!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.