我是 VB.net 的新手。我想组合两个数据网格视图,我从 CSV 文件中获取这两个数据。例如我有 Datagridview1:
Dim sr As System.IO.StreamReader = Nothing
Dim dt As New DataTable
Try
readFileName = "LNU010F" & "_" & dateParam.ToString("MM-dd-yyyy") & ".csv"
sr = New System.IO.StreamReader("C:\Documents and Settings\ucpb\Desktop\Sample CSV data\" + readFileName)
Dim newline() As String = sr.ReadLine.Split("|"c)
dt.Columns.AddRange({New DataColumn(newline(11)), New DataColumn(newline(48))})
While (Not sr.EndOfStream)
newline = sr.ReadLine.Split("|"c)
Dim newrow As DataRow = dt.NewRow
newrow.ItemArray = {newline(11), newline(48)}
dt.Rows.Add(newrow)
End While
DataGridViewCSV1.DataSource = dt
这是我从第一个代码中得到的。 http://i.stack.imgur.com/QaJZ1.png
我有 Datagridview2:
Dim delimeter As String = txtDelimiter.Text
Dim fileReader As System.IO.StreamReader = Nothing
Dim dt As New DataTable
Try
fileName = txtName.Text & "_" & dateParam.ToString("MM-dd-yyyy")
readFileName = txtName.Text & "_" & dateParam.ToString("MM-dd-yyyy") & ".csv"
fileReader = New System.IO.StreamReader("C:\Documents and Settings\ucpb\Desktop\Sample CSV data\" + readFileName)
Dim readColumn As String = fileReader.ReadLine
Dim splitColumn As String() = readColumn.Split(delimeter)
For Each arr As String In splitColumn
dt.Columns.Add(arr)
Next
Dim readRow As String = fileReader.ReadLine
Dim splitRow As String()
While readRow <> ""
splitRow = readRow.Split(delimeter)
dt.Rows.Add(splitRow)
readRow = fileReader.ReadLine()
End While
DataGridViewCSV2.DataSource = dt
这是我从第二个代码中得到的。 http://i.stack.imgur.com/r0SmT.png
我想要的是在 Datagridview2 的末尾添加UID(Datagridview1)。Acctno是关键,Datagridview2 应该与第一个 datagridview 中的 UID 相同,因为 datagridview2 中的数据没有正确排列。任何答案将不胜感激。谢谢你。