0
每个元素的频率我有一个DataGridView看起来有点像这样:如何找到在DataGridView中
ColumnName
hello
hello
bye
hello
bye
crocodile
hello
crocodile
如何找到每个元素的计数?即Hello = 4,bye = 3,鳄鱼= 2 看到它们在DataGridView列中输出。
请帮
每个元素的频率我有一个DataGridView看起来有点像这样:如何找到在DataGridView中
ColumnName
hello
hello
bye
hello
bye
crocodile
hello
crocodile
如何找到每个元素的计数?即Hello = 4,bye = 3,鳄鱼= 2 看到它们在DataGridView列中输出。
请帮
有可能是一个更好的方式来查询DataGridView
但循环和创建组,Linq
也适用。所以这是我的想法去做:
Sub CountRows()
Dim lstCountRows as List(Of String)
For Each row As DataGridViewRow In MyDataGridView.Rows
'2 is the index of the column you are querying
lstCountRows.Add(row.Cells(2).Value)
Next
'Create groups for the values on lstCountRows
Dim groups = lstCountRows.GroupBy(Function(value) value)
'Loop and print the groups count
For Each group In groups
MsgBox(group(0) & "-" & group.Count)
Next
End Sub
给它一个尝试,让我知道你的意见
你有没有考虑通过列循环和计数呢? – JohnG
如果你确实有一个DataTable,你可以查询它。 – Plutonix