Hey everyone,

Heres my problem. I have 2 forms.
Form 1 contains a menu strip and data grid view
Form 2 Contains a Button and a bunch of other controls to help create the file.

How I'm doing this

        Private Sub BtnRecord_Click(sender As Object, e As EventArgs) Handles BtnRecord.Click

        Dim Bookz As String
        Title = TxtTitle.Text
        Author = TxtAuthor.Text
        Stock = TxtStock.Text
        Price = TxtPrice.Text
        Genre = RadButFiction.Text
        Genre2 = RadButNonFiction.Text

        If TxtAuthor.Text = "" Or TxtPrice.Text = "" Or TxtTitle.Text = "" Or TxtStock.Text = "" Then
            MessageBox.Show("Please fill in all required text boxes, they are marked with a * .")
        ElseIf RadButFiction.Checked = False And RadButNonFiction.Checked = False Then
            MessageBox.Show("Please select a category.")
        ElseIf RadButFiction.Checked = True Then
            Bookz = (Title & "," & Author & "," & Stock & "," & Price & "," & Genre)
            Bookz = (Title & "," & Author & "," & Stock & "," & Price & "," & Genre2)
        End If

        S = IO.File.AppendText("Booklistz.txt")

        RadButFiction.Checked = False
        RadButNonFiction.Checked = False

So I use a streamwriter which I dim as string in the public class to make it easier.
This code is working fine.

My problem is in this code, not so much a problem as much as I don't know how to go about doing it.

I use an openfiledialog to import the textfile which was created above into the datagridview.
I ran into several problems with this code, so if anyone could please guide me into how I would go about doing this. I would be greatly appreciative.

        Dim textfile As String

            textfile = OpenFileDialog1.FileName
            DGVBooks.DataSource = IO.File.ReadAllLines(textfile)
        Catch ex As Exception
        End Try

Novice at this I'm trying to import the data so it looks like the attached capture below bd1401fb65480c8bd92bea109464a0eb ![bd1401fb65480c8bd92bea109464a0eb]

EDIT: I'm using VB.Net

I haven't tried this, but this post shows how you can read a csv file into a dataset. Once you have a dataset you should be able to set DataGridView.Datasource = to the dataset. It looks like the post is for C#, but VB .NET should be similar.

Here's another post.

Although, this post shows the way I have previously added data to a DataGridView.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.