如何使用c#将所选行的单元格与datagridview中所有其他行的单元格进行比较? [英] How do i compare the cells of a selected row with the cells of all other rows in datagridview with c#?

查看:80
本文介绍了如何使用c#将所选行的单元格与datagridview中所有其他行的单元格进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datagridview,我已经在C#winform中填充了自己。现在的问题是,我想比较所选行的单元格与所有其他行的单元格,并计算所选行的匹配单元格数量是多少其他行。

例如

如果这是数据

亲爱的是哇

是 - -

让我们哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇---- $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 1个匹配单元格,第3行包含1个匹配单元格,第4行包含0个匹配单元格。



我尝试过:



i完成了选择并且能够比较行但没有得到单元格比较和每行中匹配单元格的数量。

I have a datagridview which i have populated myself within C # winform .now problem is that i want to compare the cells of a selected row with the cells of all other rows and count that how many matching cells of selected row are there inn other rows.
for example
if this is the data
dear yes wow
for yes ----
let yes wow
dear ---- not
if 2nd row is the selected row then it should tell that first row contain 1 matching cell , 3rd row contain 1 matching cell and 4th row contain 0 matching cells.

What I have tried:

i have done with selection thing and able to compare rows but not getting cell wise comparing and number of matching cells in each row.

推荐答案

不要直接使用DataGridView - 首先使用您填充DGV的基础数据。

所以如果y你有一个List(或其他集合)或你用作DGV数据源的对象(或者你从数据库中填充的数据表)也可以使用它。

那么它几乎是一个简单的循环或者Linq语句/方法调用来进行计数。
Don't use the DataGridView directly - use the underlying data that you populated the DGV from in the first place.
So if you have a List (or other collection) or objects that you used as the DataSource for the DGV (or a DataTable you populated form an database perhaps) use that instead.
Then it's pretty much a trivial loop, or Linq statement / method call to do the counting.


这篇关于如何使用c#将所选行的单元格与datagridview中所有其他行的单元格进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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