DataGridView 匹配

发布于 2024-12-01 00:35:19 字数 3013 浏览 1 评论 0原文

我有 2 个 DataGridView (DGV)。

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

______________________________________________________________
|  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将包含这样的数据(除了更多列)

____________________________________________________________________________________________
|  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。此外,如果 PACKAGE 类型匹配并且也在下一行(如 0603),它将检查 theChipDGV 中标记为 Name 的列是否以 RC。根据它的开头,将确定将使用的 theDataBaseDGV 中的其余列。

SO:

theFinalDGV 看起来像这样:

_____________________________________________________________________________________________________________________________________________
|  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      |               |          |          |         |           |         |        |
|________|________|________|________|____________|___________|_______________|__________|__________|_________|___________|_________|________|

注意,如果没有匹配项,它会将列留空。

:

有谁知道我该怎么做吗?我主要想知道如何将一列中的值与另一列进行匹配,以及如果 theDataBaseDGV 中有多列具有相同的值......那么如何正确匹配这些列。

I have 2 DataGridViews (DGVs).

theChipDGV will contain data like this (except with many more columns):

______________________________________________________________
|  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 will contain data like this (except with many more columns):

____________________________________________________________________________________________
|  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  |
|___________|_______________|__________|__________|_________|___________|_________|_______ |

What I would like to do is match the column in theChipDGV labeled PACKAGE with the same labeled column in theDataBaseDGV. If there is a match, the entire row will be concatted into a new DGV (let's label it: theFinalDGV). Also, if the PACKAGE type is matched and is also in the next line (like 0603) it will check to see if the column labeled Name in theChipDGV starts with a R or a C. Depending on which it starts with will determine the rest of the columns from theDataBaseDGV that will be used.

SO:

theFinalDGV will look like this:

_____________________________________________________________________________________________________________________________________________
|  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      |               |          |          |         |           |         |        |
|________|________|________|________|____________|___________|_______________|__________|__________|_________|___________|_________|________|

Notice, if there is no match it leaves the columns empty.

So:

Does anyone know how I can possibly go about doing this? I mostly would like to know how to match the values from 1 column with another and if there are multiple columns from theDataBaseDGV that have the same values.. then how to properly match those.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事与诗 2024-12-08 00:35:19
            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));
                }
            }
            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));
                }
            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文