如何计算datagridview列中有多少特定值? [英] How do I count how many certain value are in a datagridview column?

查看:88
本文介绍了如何计算datagridview列中有多少特定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以计算gridview列中的某些文本数量?如果是这样,怎么样?



我有一个标签文字,它会显示gridview栏中有多少'国内'字样。例如,该列包含以下内容:



国内

外国

外国

外国

国内





单击按钮,标签文字将为2 。

Is counting how many certain text are in a gridview column possible? If so, how?

I have a label text that'll show how many the word 'Domestic' in a gridview column. If for example the column contains the following:

Domestic
Foreign
Foreign
Foreign
Domestic


The label text will be '2' in a click of a button.

推荐答案

以下代码解决了我的问题:



The following code solved my problem:

Dim x As Integer = 16

lblRows2.Text = (From Rows In DataGridView1.Rows.Cast(Of DataGridViewRow)() Where Not Rows.IsNewRow AndAlso Rows.Cells(x).Value.ToString = "Dog").Count





此代码表示该标签将计算列中Dog一词的数量。





对于本月的专家谢尔盖,您的链接没有帮助我。所以1星将会这样做。



This code means that the label will count how many the word "Dog" are in the column.


For the expert of the month, Sergey, your links didn't helped me. So 1 star will do it.


请看我对这个问题的评论。获取行,然后获取列的单元格,然后获取其值,将其与样本进行比较,遍历整个列。

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.columns%28v=vs .110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumncollection%28v=vs.110%29 .aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn%28v=vs.110%29.aspx [ ^ ],

这是获取列索引的方法: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewband.index(v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrowcollection%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow%28v=vs.110%29.aspx [< a href =http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow%28v=vs.110%29.aspxtarget =_ blanktitle =New Window> ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow .cells%28v = vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell%28v = vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.value(v = VS。 110).aspx [ ^ ]。



请参阅此代码遍历的代码示例lumn cells: https://social.msdn.microsoft.com/Forums/vstudio/en-US/10f687ed-63f3-4b57-b7d0-14714e199b4d/looping-through-cells-in-datagridview-column [ ^ ]。



-SA
Please see my comment to the question. Get rows, then column's cell, then its value, compare it with sample, traverse the whole column.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.columns%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumncollection%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn%28v=vs.110%29.aspx[^],
this is how get a column index: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewband.index(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrowcollection%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow.cells%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.value(v=vs.110).aspx[^].

See also this code sample on traversal of the column cells: https://social.msdn.microsoft.com/Forums/vstudio/en-US/10f687ed-63f3-4b57-b7d0-14714e199b4d/looping-through-cells-in-datagridview-column[^].

—SA


这篇关于如何计算datagridview列中有多少特定值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆