Click here to Skip to main content
15,898,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
 int count = dataGridView1.Rows.Cast<datagridviewrow>().Count
(row =>row.Cells["diff"].Value.ToString() >1);


What I have tried:

error in this code "operator cannot be applied to operands of type string and int "
Posted
Updated 21-Feb-17 9:40am
v2
Comments
[no name] 21-Feb-17 15:18pm    
Yes and you don't know the difference between an int and a string? What is the question?
[no name] 21-Feb-17 15:25pm    
My question is how he used condition if column content value >1 in this code
[no name] 21-Feb-17 15:32pm    
You convert the string to an int. Should be obvious, isn't it?
[no name] 21-Feb-17 15:37pm    
How do you use convert.int32 with this code?

1 solution

Hello,

you can only compare what is comparable. In this instance it should be 2 integers

The Value property of a Cell is an object and you need to convert it to an integer.

Convert.ToInt32(row.Cells["diff"].Value)>1


If you are unsure what the content of the type cell is you can find it looking at the property
ValueType


See here for details:
DataGridViewCell Class (System.Windows.Forms)[^]

Valery
 
Share this answer
 
Comments
Maciej Los 21-Feb-17 15:55pm    
Sounds reasonable ;)
5ed!
[no name] 21-Feb-17 16:33pm    
yes reasonable ^__^
[no name] 21-Feb-17 16:00pm    
Many thanks and gratitude solve problem @Valery Possoz

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