如何计算datagtidview中行[9]值> 1?的行数? [英] How to count the number of rows in datagtidview where column[9] value >1?

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

问题描述

 int count = dataGridView1.Rows.Cast<datagridviewrow>().Count
(row =>row.Cells["diff"].Value.ToString() >1);





我尝试了什么:



错误代码运算符不能应用于字符串和int类型的操作数



What I have tried:

error in this code "operator cannot be applied to operands of type string and int "

推荐答案

你好,



你只能比较可比性。在这个例子中它应该是2个整数



Cell的Value属性是一个对象,你需要将它转换为整数。



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





详情请见此处:

DataGridViewCell类(System.Windows.Forms) [ ^ ]



Valery



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

Valery


这篇关于如何计算datagtidview中行[9]值> 1?的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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