2009-12-22 81 views
0

我有一個組合框,其中IAM使用下面的代碼加載組合框。關注selectedindexchanged下拉列表

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; 

     } 

問題是在pCmbCustomer.DataSource = ds.Tables [0];組合框的選擇indexchanged事件爲i working.how可避免選擇indexchanged事件而結合組合框任何人可以幫助?

+0

你能詳細說明你的問題嗎?你如何處理你的selectedIndexChanged事件? – anonymous 2009-12-22 11:29:48

回答

1

完成綁定組合框後,您可以附加到SelectedIndexChanged事件處理程序。

因此,不要直接在用戶控件中附加事件,而是在LoadCustomer1被調用後,將其附加到LoadCustomer1的結尾或其外的代碼隱藏中。

1

儘量避免處理selectedIndexChangedEvent

避免使用pCmbCustomer.Text = "--- Select Customer Id ---";這種類型的語句。也就是說,不要明確地設置文本。

將文本"--- Select Customer Id ---"作爲列表的成員。

然後在需要時使用此pCmbCustomer.SelectedIndex = 0,2,3...,n;聲明。

相關問題