2012-10-25 25 views
-1

我有我鑄造我的下拉列表對象使用ChaseSelection類,C#有什麼不對我的循環

現在我試圖把該值從數據庫中作爲默認值在下拉列表,但似乎沒有工作,任何人都可以幫忙嗎?我甚至不認爲我的循環運行。這裏是我chaseselection類,並且也把下面的循環:由於

public class ChaseSelectionItems 
    { 
     public string code { get; set; } 
     public string text { get; set; } 

     public ChaseSelectionItems(string code, string text) 
     { 
      this.code = code; 
      this.text = text; 
     } 

     public override string ToString() 
     { 
      return this.text; 
     } 
    } 


     foreach (ChaseSelectionItems items in drpdwnChaseSecSelection.Items) 
     { 
      if (items.code == _Row.xcs_View) 
      { 
       drpdwnChaseSecSelection.SelectedValue = items.text; 
      } 
     } 
+1

放一個斷點,看看調試中發生了什麼 – Habib

+0

define「似乎並不工作」。你有編譯錯誤嗎?運行時出現異常? (哪一個?)它沒有拋出任何異常,但它不像你期待的那樣行事? –

+1

你使用哪個UI框架? WPF,WinForms等? –

回答

3

這是不完全清楚你如何配置列表框,但很有可能你沒有正確配置ValueMember。下面可能會解決這個問題:

foreach (ChaseSelectionItems items in drpdwnChaseSecSelection.Items) 
    { 
     if (items.code == _Row.xcs_View) 
     { 
      // drpdwnChaseSecSelection.SelectedValue = items.text; 
      drpdwnChaseSecSelection.SelectedItem = items; 
     } 
    } 
+0

這也不運行。它不會進入循環我認爲 –

+0

循環不會自行運行。顯示周圍的方法以及你如何/在哪裏調用它。 –