I'm trying to build a method to populate a listcontrol from a csv file. My immediate requirement is to read a two column csv file and use the fist column a listcontrol.valuemember and the second column of the csv file to be listcontrol.displaymember
My code so far,
so how do a get the data from the array either straight into the listcontrol or into a dataset?
TIA
Russ
My code so far,
Code:
Dim sAppPath As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CSVToListControl1(Me.ComboBox1, sAppPath + "\sample.csv")
End Sub
Private Sub CSVToListControl1(ByVal ListControl As ListControl, ByVal sCSVFile As String)
Dim csv_data(0, 0) As String
Dim r As Integer 'rows
Dim c As Integer 'cols
'load the two column CSV file to an array
Dim stream_reader As New StreamReader(sCSVFile)
Dim file_contents As String = stream_reader.ReadToEnd()
stream_reader.Close()
'break the file into lines.
Dim lines() As String = file_contents.Split(CChar(vbCrLf))
'break the line into columns
Dim one_line() As String = Split(lines(0), ",")
' Dimension the array.
Dim num_rows As Integer
Dim num_cols As Integer
num_rows = UBound(lines)
num_cols = UBound(one_line)
ReDim csv_data(num_rows, num_cols)
'copy the data into the array.
For r = 0 To num_rows - 1
one_line = Split(lines(r), ",")
For c = 0 To num_cols
csv_data(r, c) = one_line(c)
Next c
Next r
' Prove we have the data loaded.
For r = 0 To num_rows - 1
For c = 0 To num_cols
Debug.Write(csv_data(r, c) & "|")
Next c
Next r
End Sub
so how do a get the data from the array either straight into the listcontrol or into a dataset?
TIA
Russ