代码之家  ›  专栏  ›  技术社区  ›  Developer

如何找到DataGridView中的最后一行并将其写入文本文件

  •  2
  • Developer  · 技术社区  · 14 年前

    我想找到DataGridView的最后一行,我想把特定的行数据写到一个文本文件中,有人能帮我吗?

    1 回复  |  直到 14 年前
        1
  •  8
  •   sumit_batcoder    14 年前

     List<string> lstContents = new List<string>();
            foreach (DataGridViewCell cell in mydataGrid.Rows[mydataGrid.RowCount - 1].Cells)
            {
                lstContents .Add((string)cell.Value);
            }
     string myData= string.Join(",", lstContents.ToArray());
    

    using (StreamWriter sw = new StreamWriter(FilePath, true))
            {
                sw.WriteLine(myData);
            }