如何将 datagridview 的内容导出到文本文件 vb.net 2010

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29310656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:55:28  来源:igfitidea点击:

How to export the content of a datagridview to a text file vb.net 2010

.netvb.netvisual-studio-2010datagridviewtext-files

提问by dba2015

Please I have a datagridview that have 1 column (Customer Name) and I want export it's content in text file(c:\file.txt). how can I do that ? thanx

请我有一个包含 1 列(客户名称)的 datagridview,我想将其内容导出到文本文件(c:\file.txt)中。我怎样才能做到这一点 ?谢谢

回答by Dancho

Simplest way would be:

最简单的方法是:

Dim result As String = ""
'go through all rows
For rowNumber As Integer = 0 To DataGridView1.Rows.Count - 1
'this gets just column 0 (the first column)
    result += DataGridView1.Item(0, rowNumber).ToString
Next
'write out the string
File.WriteAllText("c:\file.txt", result)