是否可以将数据从文本文件加载到datagridview? [英] does loading data from text file to datagridview is possible?

查看:121
本文介绍了是否可以将数据从文本文件加载到datagridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为test.txt的文本文件,我想在我的数据网格视图中加载它。

在文本文件中:



Acct。号码,姓名,地址,需要

0012123123,Jef,加拿大,水

0001231542,Mel,澳大利亚,消防

..等。



这些数据应加载到我的数据网格>>

帐号名称|地址|需要|





有没有人可以教我这样做... tnx

I have a text file named test.txt and I want to load it on my datagrid view.
Inside the text file:

Acct. Number, Name, Address, Need
0012123123, Jef, Canada, Water
0001231542, Mel, Australia, Fire
..etc.

those data should load in my datagrid>>
Account Number | Name | Address | Need |


Is there anyone can teach me to do that...tnx

推荐答案

查看此链接



http://stackoverflow.com/questions/16498614/reading-from-txt-file-then-exporting-data-to-datagridview [ ^ ]


是的可能。检查下面这个链接希望这对你有帮助。



http://stackoverflow.com/questions/19582570/how-to-read -load-text-txt-file-values-in-datagridview-using-c-sharp [ ^ ]



http://stackoverflow.com/questions/16498614/reading-from-txt-file-then- export-data-to-datagridview [ ^ ]



http://stackoverflow.com/questions/7095359/putting-a-txt-file-into-a-datagridview [ ^ ]



将文本文件加载到窗口应用程序 [ ^ ]
yes its Possible.Check this links below hope this will help you.

http://stackoverflow.com/questions/19582570/how-to-read-load-text-txt-file-values-in-datagridview-using-c-sharp[^]

http://stackoverflow.com/questions/16498614/reading-from-txt-file-then-exporting-data-to-datagridview[^]

http://stackoverflow.com/questions/7095359/putting-a-txt-file-into-a-datagridview[^]

load a text file into data grid view in window application[^]


'Read the data from text file
       Dim textData As String() = System.IO.File.ReadAllLines(Me.txtSource.Text)
       Dim headers As String() = textData(0).Split(","c)

       'Create and populate DataTable
       Dim dataTable1 As New DataTable

       For Each header As String In headers
           dataTable1.Columns.Add(header, GetType(String), Nothing)
       Next
       For i As Integer = 1 To textdata.length - 1
           dataTable1.Rows.Add(textData(i).Split(","c))
       Next

       'Set the DataSource of DataGridView to the DataTable
       Me.DataGridView1.DataSource = dataTable1
       Me.Controls.Add(dataGridView1)





================ ================================================== ====

我试着研究这些代码.. anayone可以帮助我理解for循环..



======================================================================
I tried to study this codes.. Can anayone help me to understand the for loop..


这篇关于是否可以将数据从文本文件加载到datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆