Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
lastbudget and lastactual are both Lists

These lists populate 2 columns in an infragistics ultragrid

- PrevFY
- Actual_c

*So the grid has defined datasource already. These 2 columns I added programmaticly onto the grid which has a datasource.*



**(dgvBudget is the name of the ultragrid)**

int rowIndex = dgvBudget.Rows.Count;
    
    
    if (half == "Second Half Budget")
    {
        for (int i = 6; i < rowIndex; i++)
        {
            var row = dgvBudget.Rows[i];
            row.Cells["PrevFY"].Value = lastbudget[i];
            row.Cells["Actual_c"].Value = lastactual[i];
        }
        for (int i = 0; i < 6; i++)
        {
            var row = dgvBudget.Rows[i];
            row.Cells["PrevFY"].Value = lastactual[i];
            row.Cells["Actual_c"].Value = 0;
        }
    }
    else
    {
        for (int i = 0; i < rowIndex; i++)
        {
            var row = dgvBudget.Rows[i];
            row.Cells["PrevFY"].Value = lastbudget[i];
            row.Cells["Actual_c"].Value = lastactual[i];
        }
    }


My goal is to create a new datasource and import the binded data to the the datagridview with the 3 new columns I have created to cut down on MS when executing.

At the moment it is taking 8-10 seconds to execute

private void bringPreviousData()
    {
        Stopwatch stopwatch = Stopwatch.StartNew();
        List<string> lastactual = new List<string>();
        List<string> lastbudget = new List<string>();
        Control cmbBudgetCode = csm.GetNativeControlReference("17dd127e-7b02-48e9-a7bb-e98164aea713");
        EpiDataView bhView = (EpiDataView)(oTrans.EpiDataViews["GLBudgetHd"]);
        if (!dgvBudget.DisplayLayout.Bands[0].Columns.Exists("PrevFY"))
        {
            dgvBudget.DisplayLayout.Bands[0].Columns.Add("PrevFY", "Previous FY Budgeted");
            dgvBudget.DisplayLayout.Bands[0].Columns["PrevFY"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Currency;
        }

        if (!dgvBudget.DisplayLayout.Bands[0].Columns.Exists("FiscalMonth"))
        {
            dgvBudget.DisplayLayout.Bands[0].Columns.Add("FiscalMonth", "Month");
            SetColumnReadOnly("FiscalMonth", true);
        }
        else
        {
            string[] monthNames = { "April", "May", "June", "July", "August", "September", "October", "November", "December", "January", "February", "March" };
            for (int i = 0; i < monthNames.Length; i++)
            {
                dgvBudget.Rows[i].Cells["FiscalMonth"].Value = monthNames[i];
            }
        }

        string half = cmbBudgetCode.Text;
        lastactual = GetLastActual(half);
        lastbudget = GetLastBudget(half);
        int rowIndex = dgvBudget.Rows.Count;
        if (half == "Second Half Budget")
        {
            for (int i = 6; i < rowIndex; i++)
            {
                var row = dgvBudget.Rows[i];
                row.Cells["PrevFY"].Value = lastbudget[i];
                row.Cells["Actual_c"].Value = lastactual[i];
            }
            for (int i = 0; i < 6; i++)
            {
                var row = dgvBudget.Rows[i];
                row.Cells["PrevFY"].Value = lastactual[i];
                row.Cells["Actual_c"].Value = 0;
            }
        }
        else
        {
            for (int i = 0; i < rowIndex; i++)
            {
                var row = dgvBudget.Rows[i];
                row.Cells["PrevFY"].Value = lastbudget[i];
                row.Cells["Actual_c"].Value = lastactual[i];
            }
        }

        decimal total = 0m;
        foreach (UltraGridRow row in dgvBudget.Rows)
        {
            total += Convert.ToDecimal(row.Cells["PrevFY"].Value);
        }
        if (Config.typeofAccount != "Overtime")
        {
            if (GetAcctType(bhView.CurrentDataRow["SegValue1"].ToString()))
            {
                nbrPrevStatTotal.Value = total;
            }
            else
            {
                nbrPrevTotal.Value = total;
            }
        }
        else
        {
            nbrPrevTotal.Value = total;
        }
        stopwatch.Stop();
        MessageBox.Show(stopwatch.ElapsedMilliseconds.ToString());
    }


So at the moment what this code is doing is

1. Grabs 2 lists of data
2. Then adds 2 columns if they do not exist (prevFy, and FiscalMonth)
3. Then populates the ultragridview with current datasource plus my added data and columns
4. Then Sums the values in the cells to show in a text box

Could I please have some help on how I can speed this up because right now it works it does, it's just so sloooooooooooow thank you!

What I have tried:

I need to try using a binding source editing the datasource then showing the edited datasource. on the grid
Posted
Updated 4-Oct-19 6:14am
Comments
F-ES Sitecore 4-Oct-19 11:46am    
If you're adding thousands of items then it is always going to be slow, there is nothing you can do about it (however check if the component you're adding to has a bulk update mode where it doesn't re-render itself until all items are added).

If that's not the case then you need to find out exactly which operation is slow. We don't have your data so we can't do that for you. Use the Stopwatch class to time sections of your code to try and identify the bottleneck. Once found, find out why it is slow and if there is anything you can do to fix it.
Knowledged 4-Oct-19 12:22pm    
it's only 12 rows. I use a BAQ incorporated with Epicor to pull this data https://prnt.sc/pex6m0

It's only 12 rows and then that is added into a list which I then make a new column along side the grid and loop through the list setting the cells.

1 solution

If you would create a proper data source (1 collection), bind that to the grid, then the "grid" can properly "virtualize" data and speed up processing.

While "hacking" grids may seems like less work and more fun, you've defeated any special features the grid can bring to bear to speed up processing.

Virtualization - Infragistics WPF™ Help[^]
 
Share this answer
 
v3
Comments
Knowledged 4-Oct-19 12:27pm    
it's only 12 rows. I use a BAQ incorporated with Epicor to pull this data https://prnt.sc/pex6m0

It's only 12 rows and then that is added into a list which I then make a new column along side the grid and loop through the list setting the cells.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900