Struggling with Visual Basic's DataGridView

Agent67

Honorary Master
Joined
Nov 7, 2020
Messages
28,008
Reaction score
20,150
Location
Western Cape
I need some help here with the last bit of my final assignment please... So we're meant to put the contents of a 2D Array (taken from a text file) inside of a DataGridView. Now I could narrow down the problem (the 2D Array fills up correctly but...) but I'm not sure how to fill the damned dgv...

What I get:
1687773415714.png

The code:
Code:
        Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click

            'Display all quotes found in Quote.txt in the grid

            Dim lines() As String = IO.File.ReadAllLines("Quote.txt")

            Dim rows(,) As String

            ReDim rows(lines.Length - 1, 6)

            Dim line As String

            Dim data() As String


            For i As Integer = 0 To rows.GetUpperBound(0)

                line = lines(i)

                data = line.Split(","c)

                For j As Integer = 0 To rows.GetUpperBound(1)

                    rows(i, j) = data(j)

                Next

            Next

          'The problem seems to be either the query or the dgv...
            Dim query = From row In rows.Cast(Of String)()

                        Select row

            dgvQuotes.DataSource = query.ToList

            dgvQuotes.CurrentCell = Nothing

        End Sub

What the text file looks like:
POL2345,50000,10000,36,20,15,1022.22,8000
POL2345,50000,10000,36,20,15,1022.22,8000
 
bindGridview(gridnamehere);

Edit: weak answer but you need to bind the data to the grid somehow.
Typically use a data adapter, fill the adapter with data. Set the grids data source to the adapter and then do a gridname.databind
 
Last edited:
bindGridview(gridnamehere);

Edit: weak answer but you need to bind the data to the grid somehow.
Typically use a data adapter, fill the adapter with data. Set the grids data source to the adapter and then do a gridname.databind
Will look into this, thx.
 
Top
Sign up to the MyBroadband newsletter
X