读取tex文件并在数据网格视图中填充数据 [英] to read tex file and fill the data in data grid view

查看:70
本文介绍了读取tex文件并在数据网格视图中填充数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Dim  streamReader  As  IO.StreamReader =  IO.StreamReader(  D:\ PORTFOLIO1.txt

while streamReader.Peek()<> -1
Dim ROWVALUE As String
Dim CELLVALUE( 7 As 字符串
' 昏暗的MYROWCOUNT As String = DataGridView1.Rows.Count - 1
' Dim MYCOLUMCOUNT As String = DataGridView1。 ColumnCount - 1


ROWVALUE = streamReader.ReadLine()
CELLVALUE( 7 )= ROWVALUE .Split( ' 检查什么是你的分隔符
DataGridView1.Rows.Add(cellValue)
结束



文件d:portfolio1.txt包含

,N,Copper,20-05-2015, N,铜



i在运行上面的代码时遇到错误,

i请求你解决上面代码中的问题

解决方案

问题在于如何处理数组...

CELLVALUE是一个包含7个元素的字符串数组...

String.Split()返回一个数组......

但是!您尝试将该数组从Split()方法推送到CELLVALUE数组的第7个元素!!!

您应该执行以下操作:

  Dim  CELLVALUE 作为 字符串( )

CELLVALUE = ROWVALUE.Split(


Dim streamReader As IO.StreamReader = New IO.StreamReader("D:\PORTFOLIO1.txt")

While streamReader.Peek() <> -1
    Dim ROWVALUE As String
    Dim CELLVALUE(7) As String
    'Dim MYROWCOUNT As String = DataGridView1.Rows.Count - 1
    'Dim MYCOLUMCOUNT As String = DataGridView1.ColumnCount - 1


    ROWVALUE = streamReader.ReadLine()
    CELLVALUE(7) = ROWVALUE.Split(",") 'check what is ur separator
    DataGridView1.Rows.Add(cellValue)
End While


The file "d:portfolio1.txt" contains

,,N,Copper,20-05-2015,N,copper


i am facing errors when running my the above code,
i request you to solve the problem in the above code

解决方案

The problem is about how you handle arrays...
CELLVALUE is a string array of 7 elements...
String.Split() returns an array...
But! You try to push that array from Split() method into the 7th element of the CELLVALUE array!!!
You should do something like this:

Dim CELLVALUE As String()

CELLVALUE = ROWVALUE.Split(",") 


这篇关于读取tex文件并在数据网格视图中填充数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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