对C#来说还是比较新的,我试图让我的脑袋围绕适合我的应用程序的后台工作和进度条,下面的代码显示了我将一个新列添加到datagridview,然后用新列填充所有单元格零(0)。为此,实施后台工作人员和进度条的最佳方式是什么?整个过程大约需要15秒,因此需要一个进度条来显示用户正在发生的事情。datagridview中的额外列的后台工作人员和进度栏实现?
添加和填充新列的代码如下:
//Creates new column in the datagridview
DataGridViewColumn newCol = new DataGridViewColumn();
newCol.CellTemplate = new DataGridViewTextBoxCell();
newCol.HeaderText = tbAddSupp.Text.ToUpper();
newCol.Name = tbAddSupp.Text.ToUpper();
newCol.Visible = true;
dgvStock.Columns.Add(newCol);
cbSuppList.Items.Clear();
cbSuppList2.Items.Clear();
//Adds the default 0 value to all the cells in the new column
//ITS TOO SLOW THOUGH....!!!!!
int cellVal = 0;
foreach (DataGridViewRow row in dgvStock.Rows)
{
for (int r = 0; r < dgvStock.Rows.Count - 1; r++)
{
dgvStock.Rows[r].Cells[newCol.Name.ToString()].Value = cellVal;
}
}
我想你问的是错误的问题。 '如何使这个(出现)更快'将是正确的问题... – jeroenh 2012-04-11 09:52:38