2013-10-22 30 views
1

此代碼會導致DataGridView grid顯示空行,儘管它有一個柱DataPropertyName設置爲「MyProp1」:的DataGridView必然的BindingList顯示空行

public class MyClass 
{ 
    public int MyProp1; 
    public int MyProp2; 
    public int MyProp3; 
} 

public class MyItems:IListSource 
{ 
    BindingList<MyClass> _items = new BindingList<MyClass>(); 

    //.............................. 

    //IListSource 
    public bool ContainsListCollection 
    { 
     get { return false; } 
    } 

    //IListSource 
    public System.Collections.IList GetList() 
    { 
     return _items; 
    } 
} 

MyItems i = new MyItems(); 
............. 
//MyItems list is populated 
............. 
grid.DataSource = i; 

出了什麼問題?

如果我用「MyProp1」列創建DataTable,其內容以正確的方式顯示。

+1

爲什麼'ContainsListCollection'在吸氣返回'FALSE'? –

+0

你可以爲你的datagridview發佈XAML嗎? –

+0

是「WPF」還是「WinForms」?如果你的集合元素是「IList」,那麼返回值必須是真的,否則爲false。 –

回答

7

您需要更改的MyClass公共領域的相應屬性:

public class MyClass 
{ 
    public int MyProp1 { get; set; } 
    public int MyProp2 { get; set; } 
    public int MyProp3 { get; set; } 
} 
+1

+1爲觀測記錄 –

+0

它幫助!現在它甚至在'ContainsListCollection'中用'List '而不是'BindingList '和'true'或'false'也沒有任何區別。 – Paul

相關問題