我有一个combobox,其中我使用以下代码加载combobox。
public void LoadCustomer1(ComboBox pCmbCustomer)
{
obj._dtInputParameter.Clear();
obj.AddInputParameter("@Prm_OpFlag", "S", "String", 1);
//obj.strSPName = "prc_CUST_Details";
obj.strSPName = "EditCustCombo";
DataSet ds = obj.SqlExecuteFill();
pCmbCustomer.DataSource = ds.Tables[0];
pCmbCustomer.DisplayMember = "CustomerId";
pCmbCustomer.ValueMember = "CustomerId";
pCmbCustomer.Text = "--- Select Customer Id ---";
pCmbCustomer.SelectedIndex = 0;
}问题出在combobox的pCmbCustomer.DataSource = ds.Tables;selected indexchanged事件是否为working.how我可以在绑定combobox时避免选择indexchanged事件吗?有谁可以帮助我吗?
发布于 2009-12-22 18:39:39
一旦完成了组合框的绑定,就可以附加到SelectedIndexChanged事件处理程序。
因此,与其直接将事件附加到用户控件中,不如在调用LoadCustomer1后将其附加到LoadCustomer1的末尾或外部。
发布于 2009-12-22 19:33:30
尽量避免处理selectedIndexChangedEvent。
避免使用pCmbCustomer.Text = "--- Select Customer Id ---";这种类型的语句。也就是说,不要显式设置文本。
将文本设置为"--- Select Customer Id ---"作为列表的成员。
然后在需要时使用此pCmbCustomer.SelectedIndex = 0,2,3...,n;语句。
发布于 2009-12-24 22:50:12
如果可能的话,我会使用SelectionChangeCommitted而不是SelectedIndexChange。
MSDN :http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectionchangecommitted.aspx
“仅当用户更改组合框选择时才引发SelectionChangeCommitted。请勿使用SelectedIndexChanged或SelectedValueChanged捕获用户更改,,因为当选择以编程方式更改为时也会引发这些事件。”
https://stackoverflow.com/questions/1945505
复制相似问题