[英]unbound row in datagridview in c#
我有
Class A
{
private string mName;
private int mId;
private int mType;
private int mqty;
/*
property to view variables.
*/
}
BindingList<A> listofA = new BindingList<A>();
“ listofA”綁定到datagridview控件。
dataGridView1.DataSource=listofA;
顯示為。
------------------
|Name|Id|Type|Qty|
------------------
|CatA| 1| 0| 5|
|CatB| 2| 0| 6|
|DogA| 3| 1| 7|
|DogB| 4| 1| 8|
我希望顯示未綁定的行。
------------------
|Name|Id|Type|Qty|
------------------
|CatA| 1| 0| 5|
|CatB| 2| 0| 6|
|Cats|__| 0| 11| <------sum of qty
|DogA| 3| 1| 7|
|DogB| 4| 1| 8|
|Dogs|__| 1| 15| <------sum of qty
我正在考慮在“ A類”中添加一個布爾,如果為false,它將作為一項,如果為true,則作為總和。
有一個更好的方法嗎。
我要做的是RowDataBound事件中的代碼:
1)比較上一行的數據(例如:動物類型)。 如果不同,則您知道已到達類別的末尾;如果相同,則應匯總需要匯總的不同值
2a)類型相同,您做了總結,沒什么可做的了
2b)類型不同,您用總和值創建新行並重置總和變量
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.