 |
|
ขอทราบวิธีนับจำนวนข้อมูลใน gridview แบบมีเงื่อนไขค่ะ |
|
 |
|
|
 |
 |
|
ตัวอย่างจาก Stack Overflow ครับ ผมเคยนำมาใช้ Ok เลยครับ
Code (C#)
var list = myDataGridView.Rows.OfType<DataGridViewRow>()
.Select(x => x.Cells["MYCOLUMN"].Value.ToString());
var q = from x in list
group x by x into g
let count = g.Count()
orderby count descending
select new { Value = g.Key, Count = count };
where "MYCOLUMN" is the name of the column that you want, or, alternatively, you can pass the column index.
EDIT :
this code returns a list of items that contains also the list of rows with the duplications:
Code (C#)
var q = myDataGridView.Rows.OfType<DataGridViewRow>()
.GroupBy(x => x.Cells["MYCOLUMN"].Value.ToString())
.Select(g => new {Value=g.Key, Count=g.Count(), Rows=g.ToList()})
.OrderByDescending(x => x.Count);
so if you have 5 rows e.g. :
ID MYCOLUMN
0 A
1 B
2 C
3 A
4 B
will contain 3 elements:
Key="A", Count=2, Rows={ [0 - A] [3 - A]}
Key="B", Count=2, Rows={ [1 - B] [4 - B]}
Key="C", Count=1, Rows={ [2 - C] }
|
 |
 |
 |
 |
Date :
2012-04-12 20:48:59 |
By :
SharpDev |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
 ขอบคุณค่ะ เดี๋ยวจะลองดู
|
 |
 |
 |
 |
Date :
2012-04-14 08:20:37 |
By :
biw |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ดที่ให้มา มันจะแสดงผลลัพธ์ที่ตรงไหนคะ
|
 |
 |
 |
 |
Date :
2012-04-14 08:28:15 |
By :
biw |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|