保存 DataGridView

发布于 2024-12-03 01:33:04 字数 1467 浏览 1 评论 0原文

我将两个文件打开到 2 个单独的 DGV 中。打开并单击“格式”按钮后,它会匹配两个单独的 DGV 中的所有行并将其复制到新的 DGV 中。

第一个 DGV 如下所示(列标签):

Name    P/N    X    Y    Rotation    PkgStyle

第二个 DGV 如下所示:

PkgStyle    P/D   Feeder    Vision    Speed    Machine    Width    Time

这两个文件将匹配 PkgStyle 并将其余行连接在一起,得到如下所示的第三 DGV:

Name    P/N    X    Y    Rotation    PkgStyle    PkgStyle    P/D   Feeder    Vision    Speed    Machine    Width    Time

现在,正如您所料,可能存在不正确匹配的行,并且不会组合两个文件中的两组行。如果是这种情况,它将仅输入第一个文件中的信息,而不是第二个文件中的信息。

因此,一些示例数据可能如下所示:

Name    P/N    X    Y    Rotation    PkgStyle    PkgStyle    P/D   Feeder    Vision    Speed    Machine    Width    Time
J11     1234   12  7     180         9876         9876    THETHING   1        1           1        UNI      12MM     1MS
R90     2222   19  9     0           1255         1255    ITEM       2        1           1        UNI2     5MM      1MS
J18     9845   11  4     270         456
C127    1111   05  1     270         5555         5555    ITEM2      3        1           1        UNI      8MM      0.1MS

SO

第三行(不包括列标题)中有空白单元格。当用户更改这些空白点中的单元格数据时,我想将其添加到已经包含类似数据的文本文档中。因此,如果用户将 456 someITEM 4 1 1 UNI2 9MM 10MS 添加到空白的 DataGridView 行,我想将其添加到已包含数据的文件的末尾。我只想在每行的所有列单元格都已填充的情况下添加该行。输出只能用空格分隔。

谁能帮我解决这个问题吗?

I open two files into 2 seperate DGVs.. Once opened and the button "Format" is clicked, it matches all of the lines in the two seperate DGVs and copies it into a new DGV.

The first DGV looks like this (column labels):

Name    P/N    X    Y    Rotation    PkgStyle

and the second DGV looks like this:

PkgStyle    P/D   Feeder    Vision    Speed    Machine    Width    Time

The two files will match the PkgStyle and concat the rest of the lines together to get the third DGV that looks like this:

Name    P/N    X    Y    Rotation    PkgStyle    PkgStyle    P/D   Feeder    Vision    Speed    Machine    Width    Time

Now, as you may expect there could be possible lines that do not match properly and will not combine the two sets of lines from the two files. If this is the case it will only input the information from the first file and not the second.

So some sample data might look like this:

Name    P/N    X    Y    Rotation    PkgStyle    PkgStyle    P/D   Feeder    Vision    Speed    Machine    Width    Time
J11     1234   12  7     180         9876         9876    THETHING   1        1           1        UNI      12MM     1MS
R90     2222   19  9     0           1255         1255    ITEM       2        1           1        UNI2     5MM      1MS
J18     9845   11  4     270         456
C127    1111   05  1     270         5555         5555    ITEM2      3        1           1        UNI      8MM      0.1MS

SO

The third row (not including the titles of the columns) has blank cells in it. When the user changes the cell data in those blank spots, I would like to add it to a text document that already contains similar data. So, if the user added 456 someITEM 4 1 1 UNI2 9MM 10MS to the DataGridView lines that were blank, I want to add that to the end of the a file that already contains data. I want to only add the line if all of the column cells are filled in for each row. The output can just be space delimited.

Can anyone help me with this?

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

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

发布评论

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

评论(2

久夏青 2024-12-10 01:33:04

您可以使用此链接检查所选单元格是否为空/空,并进行一些修改:C# DataRow Empty-check

我想相应地有 3 个数据网格:dg1、dg2、dg3。 dg3 的列由 dg1 和 dg2 的列组成。

public static string GetNewData(DataRow row)
{
  string res = string.Empty;
  if (row == null) throw new ArgumentNullException("row");

  foreach (DataColumn column in dg2.Columns)
    if (row.IsNull(column.ColumnName) || string.IsNullOrEmpty(row[column.ColumnName].ToString()))
      return string.Empty;
    else
      res += row[column.ColumnName] + " ";

  return res.Trim();
}

希望这有帮助。

You can use this link to check selected cell is null/empty or not with some modification: C# DataRow Empty-check

I suppose 3 datagrid: dg1, dg2, dg3 accordingly. Columns of dg3 compose of columns of dg1 and dg2.

public static string GetNewData(DataRow row)
{
  string res = string.Empty;
  if (row == null) throw new ArgumentNullException("row");

  foreach (DataColumn column in dg2.Columns)
    if (row.IsNull(column.ColumnName) || string.IsNullOrEmpty(row[column.ColumnName].ToString()))
      return string.Empty;
    else
      res += row[column.ColumnName] + " ";

  return res.Trim();
}

Hope this help.

近箐 2024-12-10 01:33:04
foreach (var line in theList)
{
    string pkgStyleNA, PDNA, feederNA, visionNA, speedNA, machineNA, widthNA, timeNA;

    if (line.PkgStyle.Equals(string.Empty))
        pkgStyleNA = "N/A ";
    else
        pkgStyleNA = line.PkgStyle;

    if (line.PD.Equals(string.Empty))
        PDNA = "N/A ";
    else
        PDNA = line.PD;

    if (line.Feeder.Equals(string.Empty))
        feederNA = "N/A ";
    else
        feederNA = line.Feeder;

    if (line.Vision.Equals(string.Empty))
        visionNA = "N/A ";
    else
        visionNA = line.Vision;

    if (line.Speed.Equals(string.Empty))
        speedNA = "N/A ";
    else
        speedNA = line.Speed;

    if (line.Machine.Equals(string.Empty))
        machineNA = "N/A ";
    else
        machineNA = line.Machine;

    if (line.Width.Equals(string.Empty))
        widthNA = "N/A ";
    else
        widthNA = line.Width;

    if (line.Time.Equals(string.Empty))
        timeNA = "N/A ";
    else
        timeNA = line.Time.ToString();

    addToDataBase.Add(pkgStyleNA + " " + PDNA + " " + feederNA + " " + visionNA + " " + speedNA+ " " + machineNA+ " " + widthNA + " " + timeNA);
}

using (StreamWriter outFile = new StreamWriter(openDataBaseFile.FileName, true))
{
    outFile.WriteLine();

    var noDuplicatesList = addToDataBaseList.Distinct().ToList();
    foreach (var item in noDuplicatesList)
        outfile.WriteLine(item);
}
foreach (var line in theList)
{
    string pkgStyleNA, PDNA, feederNA, visionNA, speedNA, machineNA, widthNA, timeNA;

    if (line.PkgStyle.Equals(string.Empty))
        pkgStyleNA = "N/A ";
    else
        pkgStyleNA = line.PkgStyle;

    if (line.PD.Equals(string.Empty))
        PDNA = "N/A ";
    else
        PDNA = line.PD;

    if (line.Feeder.Equals(string.Empty))
        feederNA = "N/A ";
    else
        feederNA = line.Feeder;

    if (line.Vision.Equals(string.Empty))
        visionNA = "N/A ";
    else
        visionNA = line.Vision;

    if (line.Speed.Equals(string.Empty))
        speedNA = "N/A ";
    else
        speedNA = line.Speed;

    if (line.Machine.Equals(string.Empty))
        machineNA = "N/A ";
    else
        machineNA = line.Machine;

    if (line.Width.Equals(string.Empty))
        widthNA = "N/A ";
    else
        widthNA = line.Width;

    if (line.Time.Equals(string.Empty))
        timeNA = "N/A ";
    else
        timeNA = line.Time.ToString();

    addToDataBase.Add(pkgStyleNA + " " + PDNA + " " + feederNA + " " + visionNA + " " + speedNA+ " " + machineNA+ " " + widthNA + " " + timeNA);
}

using (StreamWriter outFile = new StreamWriter(openDataBaseFile.FileName, true))
{
    outFile.WriteLine();

    var noDuplicatesList = addToDataBaseList.Distinct().ToList();
    foreach (var item in noDuplicatesList)
        outfile.WriteLine(item);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文