CSV files, Linq, Data Grid View, Binding Sources

I am unable to enumerate into a data grid view of a generic list of generic list of string.  The goal is to load a csv file into a datagridview

The code so far

   Private Sub cmdLoadFile_Click(sender As System.Object, e As System.EventArgs) Handles cmdLoadFile.Click
        Dim AsTable As New Generic.List(Of Generic.List(Of String))
            Using reads As StreamReader = New StreamReader(txtPath.Text)
                Dim RAW As String = reads.ReadLine
                Do While (Not RAW Is Nothing)
                    Dim AsRow As New Generic.List(Of String)
                    RAW = reads.ReadLine
            End Using


            Dim TariffBinder As New BindingSource
            TariffBinder.DataSource = AsTable
            dgvCSVRAW.DataSource = TariffBinder
        Catch ex As Exception

        End Try

    End Sub

I am fairly certain the results I get so far are the properties of the genric list of string so I get Capacity and Count properties as the returned values not the list's content.

I am a little unsure how to get to them at the moment any help would be good

Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:
Create a new class that represents the fields of your CSV. Then create a list of that new class.


Dim AsTable As New Generic.List(Of YourNewClass)()

Open in new window

Then loop through your file, creating new instances of YourNewClass, populated with the data from a line of your CSV, and added to this list. Once you have looped the file, then data-bind your list to the DGV. Make sure the field names of your file are the property names of YourNewClass. That should give you desirable results.
AlyantoAuthor Commented:
Hi Kaufmed
I was hoping to be able to enumerate the nested generic list of string.  I can not be certain of the number of columns I am pulling in.  I could make a more complex dynamic set of classes but this seems to be a very simple mans to achive what is needed.

I could have a set of classes structured in this way
MyTable that is composed of class MyRow that in turn is composed of MyCell Class.  But is seems such a long hand way if only I could get at the generic list of string instead and its values.

käµfm³d 👽Commented:
Well the problem, as you have witnessed, is that data binding iterates over the Public properties of the class found within the collection. In this case that is String, and its Public properties are Length--at least in my testing; you might be targeting a different version of the Framework than I am. This is why I suggested the class, because then you are creating the Public properties that should be displayed within the DGV.

Another alternative would be to abandon data binding and create the columns yourself.
AlyantoAuthor Commented:
I had hoped to get another answer but alas Kaufmed you are right on the ball.  

Many Thanks

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.