DataGridView won't show my Data

StevenAndries

New member
Joined
Feb 21, 2007
Messages
2
Programming Experience
Beginner
Hello community,

I'll start like a lot of people start their threads: I'm new to programming.

Anyway, I've been trying to create a program that reads tab delimited text files and shows the data in a DataGridView (and later on, I'll have to copy the DataSet data to a DataBase.. but those are problems for later).

Anyway, I have my form with a DataSet dsFile, a DataGridView DataGridView1 and a MenuStrip MenuStrip1.
My form holds the following Code:

VB.NET:
    Private Sub TextFileLadenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextFileLadenToolStripMenuItem.Click
        Dim myStream As IO.Stream = Nothing
        Dim dtTable As DataTable = dsFile.Tables.Add("Artikels")

        'Alle kolommen toevoegen aan DataSet
        dtTable.Columns.Add("Description")
        dtTable.Columns.Add("ArtId")
        dtTable.Columns.Add("PartID")
        dtTable.Columns.Add("Class1")
        dtTable.Columns.Add("Class2")
        dtTable.Columns.Add("Class3")
        dtTable.Columns.Add("PublisherName")
        dtTable.Columns.Add("Version")
        dtTable.Columns.Add("Language")
        dtTable.Columns.Add("Media")
        dtTable.Columns.Add("Trend")
        dtTable.Columns.Add("PriceGroup")
        dtTable.Columns.Add("PriceCode")
        dtTable.Columns.Add("LP_Bef")
        dtTable.Columns.Add("DE_Bef")
        dtTable.Columns.Add("D1_Bef")
        dtTable.Columns.Add("D2_Bef")
        dtTable.Columns.Add("LP_Eur")
        dtTable.Columns.Add("DE_Eur")
        dtTable.Columns.Add("D1_Eur")
        dtTable.Columns.Add("D2_Eur")
        dtTable.Columns.Add("StockIndication")
        dtTable.Columns.Add("BackorderDate")
        dtTable.Columns.Add("ModifDate")
        dtTable.Columns.Add("EanCode")



        Dim fileOpen As OpenFileDialog = New OpenFileDialog
        fileOpen.InitialDirectory = "c:\"
        fileOpen.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
        fileOpen.FilterIndex = 2
        fileOpen.RestoreDirectory = True

        If fileOpen.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            Try
                myStream = fileOpen.OpenFile()
                If (myStream IsNot Nothing) Then

                    ' Stream lezen
                    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(fileOpen.FileName.ToString)
                        MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
                        MyReader.Delimiters = New String() {vbTab}
                        Dim currentRow As String()
                        'Loop door alle velden
                        'Indien corrupte lijn, geef error weer en doe door met parsen 
                        While Not MyReader.EndOfData
                            Try
                                currentRow = MyReader.ReadFields()
                                ' Include code here to handle the row.
                                dtTable.Rows.Add(currentRow)
                            Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                                MsgBox("Lijn " & ex.Message & " is fout.  Wordt overgeslagen")
                            End Try
                        End While
                        'refresh DataGridView
                        DataGridView1.DataSource = dsFile.Tables("Artikels")
                        DataGridView1.Refresh()
                    End Using


                End If
            Catch Ex As Exception
                MessageBox.Show("Kan bestand niet lezen. Error bericht: " & vbCrLf & Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Finally
                'Dubbelchecken voor de zekerheid dat we geen exception hebben gekregen bij het openen
                If (myStream IsNot Nothing) Then
                    myStream.Close()
                End If
            End Try
        End If
    End Sub
My problem: whenever I load the Text File, it doesn't do anything.. It just hangs for a second or two, but that's it.

Anyone any ideas?
 
The problem is here:
VB.NET:
                        'refresh DataGridView
                        DataGridView1.DataSource = dsFile.Tables("Artikels")
                        DataGridView1.Refresh()

Changed it to:

VB.NET:
                        'refresh DataGridView
                        DataGridView1.DataSource = dtTable
                        DataGridView1.Refresh()
Still the same problem..
 
Back
Top