2012-10-25 26 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

循环不会自行运行。显示周围的方法以及你如何/在哪里调用它。 –