首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataGridView匹配

DataGridView匹配
EN

Stack Overflow用户
提问于 2011-08-20 23:41:58
回答 1查看 222关注 0票数 0

我有两个DataGridViews (DGVs)。

theChipDGV将包含这样的数据(除了有更多的列)

代码语言:javascript
复制
______________________________________________________________
|  NAME  |  P/N   |  X     |  Y     |  ROTATION  |  PACKAGE  |
|________|________|________|________|____________|___________|
| R16    | 147479 | 20.325 | 100.000| 0          | 0603      |
| C6     | 14739  | -5.325 | -10.105| 180        | 0603      |
| U45    | 123456 | 12.345 | 12.345 | 45         | 0402      |
|________|________|________|________|____________|___________|

theDataBaseDGV将包含这样的数据(除了有更多的列)

代码语言:javascript
复制
____________________________________________________________________________________________
|  PACKAGE  |  DESCRIPTION  |  FEEDER  |  VISION  |  SPEED  |  MACHINE  |  WIDTH  |  TIME  |
|___________|_______________|__________|__________|_________|___________|_________|_______ |
| PLCC20    |  N/A          | 25MM     |  N/A     |  3      | UNIVERSAL |  12MM   |  0.05  |
| 0603      |  0603C_1.0    | 8X4      |  1       |  1      |   FUJI-1  |  8MM    |  20    |
| 0603      |  0603R_1.0    | 12X4     |  1       |  5      |   FUJI-2  |  16MM   |  0.20  |
|___________|_______________|__________|__________|_________|___________|_________|_______ |

我想要做的是将theChipDGV标记的PACKAGE中的列与theDataBaseDGV.中的相同标记列匹配。如果有匹配,整个行将被连接到一个新的DGV中(让我们标记它:theFinalDGV__). )此外,如果包类型匹配并且也在下一行(如0603),它将检查theChipDGV中标有theChipDGV的列是否以RC开头。根据它以哪个开头开始,将确定将使用的theDataBaseDGV中的其余列。

SO:

theFinalDGV将如下所示:

代码语言:javascript
复制
_____________________________________________________________________________________________________________________________________________
|  NAME  |  P/N   |  X     |  Y     |  ROTATION  |  PACKAGE  |  DESCRIPTION  |  FEEDER  |  VISION  |  SPEED  |  MACHINE  |  WIDTH  |  TIME  |
|________|________|________|________|____________|___________|_______________|__________|__________|_________|___________|_________|________|
| R16    | 147479 | 20.325 | 100.000| 0          | 0603      |  0603R_1.0    | 12X4     | 1        | 5       | FUJI-2    | 16MM    | 0.20   |
| C6     | 14739  | -5.325 | -10.105| 180        | 0603      |  0603C_1.0    | 8X4      | 1        | 1       | FUJI-1    | 8MM     | 20     |
| U45    | 123456 | 12.345 | 12.345 | 45         | 0402      |               |          |          |         |           |         |        |
|________|________|________|________|____________|___________|_______________|__________|__________|_________|___________|_________|________|

注意,如果没有匹配,则保留列为空.

所以:

有人知道我该怎么做吗?我主要想知道如何将1列的值与另一列的值匹配,以及是否有来自theDataBaseDGV的多个列具有相同的值。那么如何正确地匹配这些。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-22 11:04:26

代码语言:javascript
复制
            int chipRowCount = theChipDGV.RowCount;
            int dataBaseRowCount = theDataBaseDGV.RowCount;

            for (int count = 0; count < chipRowCount; count++)
            {
                for (int i = 0; i < dataBaseRowCount; i++)
                {
                    if (theChipList[count].PkgStyle.Equals(theDataBaseList[i].PackageType) || (theChipList[count].PkgStyle.Contains(theDataBaseList[i].PackageType) &&
                        theDataBaseList[i].PartDescription.Contains("R") && theChipList[count].Name.StartsWith("R")) || ((theChipList[count].PkgStyle.Contains(theDataBaseList[i].PackageType) &&
                        theDataBaseList[i].PartDescription.Contains("C") && theChipList[count].Name.StartsWith("C"))))
                    {
                        if (!theChipList[count].Used)
                        {
                            theChipList[count].Used = true;
                            theFinalList.Add(new LoadLine(theChipList[count].Name, theChipList[count].PartNumber,
                                theChipList[count].XPlacement, theChipList[count].YPlacement, theChipList[count].Rotation,
                                theChipList[count].PkgStyle, theDataBaseList[i].PackageType, theDataBaseList[i].PartDescription,
                                theDataBaseList[i].Feeder, theDataBaseList[i].Vision, theDataBaseList[i].Speed,
                                theDataBaseList[i].Machine, theDataBaseList[i].TapeWidth, 0));

                            theFinalDGV.DataSource = theFinalList;
                        }
                    }
                }
            }

            for (int count = 0; count < theChipList.Count; count++)
            {
                if (!theChipList[count].Used)
                {
                    theFinalList.Add(new LoadLine(theChipList[count].Name, theChipList[count].PartNumber,
                        theChipList[count].XPlacement, theChipList[count].YPlacement, theChipList[count].Rotation,
                        theChipList[count].PkgStyle, string.Empty, string.Empty, string.Empty, string.Empty,
                        string.Empty, string.Empty, string.Empty, 0));
                }
            }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7135419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档