2009-10-08 44 views
1

我有下面提到的方法,我將DataSource綁定到組合框控件。在將數據源綁定到組合框時的錯誤

// floorLocnList is coming from a webservice method 
    private void lstFloor_BindFloor(FloorLocModel[] floorLocnList) 
    { 
     this.comboBox1.DataSource = floorLocnList;   
     this.comboBox1.DisplayMember = "Location"; 
     this.comboBox1.ValueMember = "FloorLoc"; 
    } 

和類這樣

[Serializable] 
public class FloorLocModel 
{ 
    private int floorLoc; 
    private string location; 

    public int FloorLoc 
    { 
     get 
     { 
      return this.floorLoc; 
     } 
     set 
     { 
      this.floorLoc = value; 
     } 
    } 

    public string Location 
    { 
     get 
     { 
      return this.location; 
     } 
     set 
     { 
      this.location = value; 
     } 
    } 
} 

定義顯示錯誤值沒有在預期的範圍內伸手ValueMember

Bug Detail: 

    at System.Windows.Forms.ListControl._SetDataBinding(Object newDataSource, BindingMemberInfo newDisplayMember, Boolean fForceRebind) 
    at System.Windows.Forms.ListControl.set_ValueMember(String value) 
    at IdineSmart.frmLogin.lstFloor_BindFloor(FloorLocModel[] floorLocnList) 
    at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) 
    at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess, StackCrawlMark& stackMark) 
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) 
    at System.Windows.Forms.Control.TASK.Invoke() 
    at System.Windows.Forms.Control._InvokeAll() 
    at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam) 
    at System.Windows.Forms.ListView.WnProc(WM wm, Int32 wParam, Int32 lParam) 
    at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam) 
    at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal) 
    at System.Windows.Forms.Form.ShowDialog() 
    at IdineSmart.frmMain.frmMain_Load(Object sender, EventArgs e) 
    at System.Windows.Forms.Form.OnLoad(EventArgs e) 
    at System.Windows.Forms.Form._SetVisibleNotify(Boolean fVis) 
    at System.Windows.Forms.Control.set_Visible(Boolean value) 
    at System.Windows.Forms.Application.Run(Form fm) 
    at IdineSmart.Program.Main() 

的價值分配後下降它工作正常,但我dono蘇它開始給我提出這個問題。當我調試代碼值成員顯示空字符串,即使我分配它,可能是這個問題,但它是如何發生這樣的。請幫幫我。

在此先感謝。

回答

1

我不確定,但我想我有同樣的問題。

嘗試在最後更改序列 - 數據源。

this.comboBox1.DisplayMember = "Location"; 
    this.comboBox1.ValueMember = "FloorLoc"; 
    this.comboBox1.DataSource = floorLocnList;  
+0

它綁定對象,但顯示** MobileTest.TestProxy.FloorLocModel **。你有沒有爲它做任何工作..? – 2009-10-08 09:03:44

+0

謝謝,在我的情況下,這是解決方案 – Undercover1989 2015-11-27 12:25:01

0

我終於找到了。 其全部因爲顯示爲的錯誤消息。但實際問題是我的項目中有幾個用戶控件是針對平臺Pocket PC 2003 SDK和主要項目是針對Pocket PC 2005 SDK。所以我讓我的所有項目都針對相同的SDK,然後解決問題。

任何方式感謝您的答覆。