2011-08-06 134 views
1

是否可能將複雜列表綁定到DataSource與所有成員的GridView?將複雜列表綁定到數據源gridview

如:

public class Car 
    { 
     private string _make; 
     private string _model; 
     private int _year; 
     private int _speedCollection; 

     public Car(string make, string model, int year) 
     { 
      _make = make; 
      _model = model; 
      _year = year; 
     } 

     public string Make 
     { 
      get { return _make; } 
      set { _make = value; } 
     } 

     public string Model 
     { 
      get { return _model; } 
      set { _model = value; } 
     } 

     public int Year 
     { 
      get { return _year; } 
      set { _year = value; } 
     } 

     public List<MyClass> SpeedColections 
     { 

      get { return _speedCollection; } 
      set { _speedCollection = value; } 


     } 


    } 


    public class MyClass 
    { 
     private int _speed; 
     public int Speed 
     { 
      get { return _speed; } 
      set { _speed = value; } 
     } 
    } 

回答

3

是的,這是可能的。而且它會工作,除了SpeedCollections成員,除非你指定的其他公共成員,將返回,說,Speed的字符串表示(逗號分隔值或這一類的東西)

更新

這是會返回SpeedCollections的字符串表示的成員的示例:

警告!未來潛在的僞代碼,我目前還不能編譯或測試,因此需要

public string SpeedRepresentation 
{ 
    get 
    { 
     return string.Join(",", 
          _speedCollection.Select(s => s.Speed().ToString()) 
              .ToArray()); 
    } 
} 
+0

時,請給我一個樣品作調節。 –

+0

有你的樣品。 –