Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.
Posted
Updated 13-Jan-15 6:12am
v3
Comments
Sergey Alexandrovich Kryukov 13-Jan-15 11:12am    
What's wrong with reading original MSDN documentation? It is crystal clear on this topic.
—SA
[no name] 13-Jan-15 11:20am    
What MSDN documentation??
Sergey Alexandrovich Kryukov 13-Jan-15 11:31am    
Which part of this you don't know? MSDN? documentation? This is the main documentation you use when doing .NET programming, and a lot more. If you don't you don't do any programming.
—SA
[no name] 14-Jan-15 0:01am    
Because you don't get my question as it is. The question is clear from its title.

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


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.
 
Share this answer
 
 
Share this answer
 
Comments
[no name] 13-Jan-15 11:48am    
Please answer my question, not giving me links. I already know about this I just need the answer to this question.
Sergey Alexandrovich Kryukov 13-Jan-15 11:52am    
No, you don't know it. If you knew, you would not ask your question, because everything is in documentation. Don't expect that people will spend time on writing extremely trivial but relatively long code for you in all cases. See the very last link for some code sample.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900