form上使用combobox控件,初始化给combobox添加项时为何速度很慢?代码如下:
cbo.BeginUpdate(); cbo.Items.Clear();
if (blnFirstBlank)
{
cbo.Items.Add("");
}
foreach (TListConst lst in lstConst)
{
Debug.PrintWithTime("InitComboBox 1");
cbo.Items.Add(lst.strInteriorId + "-" + lst.strConstDisplayName);
Debug.PrintWithTime("InitComboBox 2");
} cbo.EndUpdate();
打印出的时间如下:
[2010-01-13 14:33:02.499]:InitComboBox 1
[2010-01-13 14:33:02.546]:InitComboBox 2
[2010-01-13 14:33:02.546]:InitComboBox 1
[2010-01-13 14:33:02.577]:InitComboBox 2
[2010-01-13 14:33:02.577]:InitComboBox 1
[2010-01-13 14:33:02.624]:InitComboBox 2使用cbo.Items.Add添加一项居然要花费近40ms时间,太夸张了!改用AddRange方法尝试一样很慢。
请高人指点问题出在哪里?
cbo.BeginUpdate(); cbo.Items.Clear();
if (blnFirstBlank)
{
cbo.Items.Add("");
}
foreach (TListConst lst in lstConst)
{
Debug.PrintWithTime("InitComboBox 1");
cbo.Items.Add(lst.strInteriorId + "-" + lst.strConstDisplayName);
Debug.PrintWithTime("InitComboBox 2");
} cbo.EndUpdate();
打印出的时间如下:
[2010-01-13 14:33:02.499]:InitComboBox 1
[2010-01-13 14:33:02.546]:InitComboBox 2
[2010-01-13 14:33:02.546]:InitComboBox 1
[2010-01-13 14:33:02.577]:InitComboBox 2
[2010-01-13 14:33:02.577]:InitComboBox 1
[2010-01-13 14:33:02.624]:InitComboBox 2使用cbo.Items.Add添加一项居然要花费近40ms时间,太夸张了!改用AddRange方法尝试一样很慢。
请高人指点问题出在哪里?
{
private string strName;
private object id; public object ID
{
get { return id; }
set { id = value; }
} public string NAME
{
get { return strName; }
set { strName = value; }
}
}; Debug.PrintWithTime("..........1");
ArrayList lstArray = new ArrayList();
for (int i = 0; i < 5; i++)
{
TT t = new TT();
t.ID = "22";
t.NAME = "ddddd";
lstArray.Add(t);
}
Debug.PrintWithTime("..........1.5"); cboSendFlag.DataSource = lstArray;
cboSendFlag.DisplayMember = "NAME";
cboSendFlag.ValueMember = "ID";
Debug.PrintWithTime("..........2");打印时间如下:
[2010-01-13 15:13:17.487]:..........1
[2010-01-13 15:13:17.503]:..........1.5
[2010-01-13 15:13:18.174]:..........2数据绑定居然花掉600ms时间!这个不正常吧?请帮忙看看代码是否有问题