lastbudget和lastactual都是列表
这些列表填充了基础设施超网格中的2列
因此,网格已经定义了数据源。我以编程方式将这两列添加到了具有数据源的网格中。
(dgvBudget是超网格的名称)
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];
}
}
我的目标是创建一个新的数据源,并使用我创建的3个新列将绑定的数据导入到datagridview中,以在执行时减少MS。
目前执行过程需要8到10秒
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());
}
因此,此代码目前正在执行
请问我如何加快速度,因为现在它可以工作了,真是太好了,谢谢!