我有大型列表(超过12000项),应该在ComboBox中显示。 ComboBox绑定到列表:
this.cmbMCBCode.DataSource = GlobalProperties.MCBCodeList;
this.cmbMCBCode.DisplayMember = "MCBCode";
this.cmbMCBCode.ValueMember = "Id";
绑定需要很长时间(约5-7秒),并且,正如每次表单加载时一样,用户感觉不舒服。我试图在内存中填充已填充的ComboBox,直到下一次表单加载为止:
if ( Program.MainForm.MCBCodeComboBox.Item ==0 )
{
this.cmbMCBCode.DataSource = GlobalProperties.MCBCodeList;
this.cmbMCBCode.DisplayMember = "MCBCode";
this.cmbMCBCode.ValueMember = "Id";
Program.MainForm.MCBCodeComboBox = this.cmbMCBCode;
}
else
{
this.cmbMCBCode = Program.MainForm.MCBCodeComboBox;
this.cmbMCBCode.DisplayMember = "MCBCode";
this.cmbMCBCode.ValueMember = "Id";
}
但在this.cmbMCBCode = Program.MainForm.MCBCodeComboBox
之后,虽然两个变量中的字段相等,但cmbMCBCode不会在表单上显示任何内容。