Hi there,
I have a csv file which i would like to display in a control on my form which behaves like excel spreadsheet.
here is a screenshot of the datatable which i use to put the data on. Is there a more efficient way of doing this ?
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim SR As StreamReader = IO.File.OpenText("badger.csv") Dim strFileString As String Dim al As New ArrayList Dim filetext() As String Dim i, j As Integer Dim dt As New DataTable Dim dr As DataRow Do While SR.Peek <> -1 al.Add(SR.ReadLine) Loop filetext = Split(al(0), ",") For j = 0 To filetext.Length - 1 ListBox1.Items.Add(filetext(j)) dt.Columns.Add(filetext(j)) Next For i = 1 To al.Count - 1 Dim r As DataRow = dt.NewRow filetext = Split(al(i), ",") For j = 0 To filetext.Length - 1 'ListBox1.Items.Add(filetext(j)) r(j) = filetext(j) Next dt.Rows.Add(r) ' ListBox1.Items.Add(filetext(3).ToString) Next DataGrid1.DataSource = dt End Sub
Any ideas folks ?




Reply With Quote