0
讓我們這些類:如何在c#中的gridview固定字段和動態列表中顯示?
public class MyObject
{
//constructor and other stuff
public bool MyBool { get; set; }
public string MyString { get; set; }
public double MyDouble { get; set; }
...
public List<MyProperty> Properties { get; set; }
}
public class MyProperty
{
//constructor and other stuff
public Type TheType { get; set; }
public String Name { get; set; }
public Object Value { get; set; }
}
在窗體我將填充值:
MyObject myObject = new MyObject(true, "Foo", 12);
MyObject myObject2 = new MyObject(false, "Bar", 16);
myObject.Properties.Add(new MyProperty(typeof(double),"Amount",2000));
myObject.Properties.Add(new MyProperty(typeof(string),"Name","Ale"));
//in the same order, with the same type and name
//only the values are different
myObject2.Properties.Add(new MyProperty(typeof(double),"Amount",3000));
myObject2.Properties.Add(new MyProperty(typeof(string),"Name","Teru"));
List<MyObject> list = new List<MyObject>();
list.Add(myObject);
list.Add(myObject2);
現在的問題是:我怎麼能顯示固定字段和動態的定義的屬性單個datagridview? 最終的結果應該是這樣的:
MyBool | MyString | MyDouble | Amount | Name
true | Foo | 12 | 2000 | Ale
false | Bar | 16 | 3000 | Teru
任何意見或暗示的歡迎。