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))
        Try
            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)
                    AsRow.AddRange(RAW.Split(","))
                    AsTable.Add(AsRow)
                    RAW = reads.ReadLine
                Loop
            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

/Aly
LVL 1
AlyantoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Create a new class that represents the fields of your CSV. Then create a list of that new class.

e.g.

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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

/Aly
0
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.
0
AlyantoAuthor Commented:
I had hoped to get another answer but alas Kaufmed you are right on the ball.  

Many Thanks

/Aly
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.