[英]Verify if GridView cell values are same on 3 column
How can I validate 3 column cell values are same on the grid view. 如何验证3个列单元格值在网格视图上相同。 My code some how not working.O have 4 rows and 3 columns gridview.
我的代码有些不起作用。O有4行3列gridview。 third column has all the different values... In this case my button1 has to be false.
第三列具有所有不同的值...在这种情况下,我的button1必须为false。 but it comes true
但这是真的
code 码
var isSame = dataGridView1.Rows.Cast<DataGridViewRow>()
.Select(x => Convert.ToString(x.Cells[2].Value))
.Distinct().Count() == 1;
if (!isSame)
{
button1.Enabled = true;
return;
}
I would do this, it is simpler in my mind. 我会这样做,在我看来更简单。
var x = (from x in GridView1.Rows
select x[2]).Distinct().ToList();
if (x.Count == 1)
{
//they are all the same
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.