CSV as datasource.

Jun 8, 2013 at 7:57 PM
Edited Jun 12, 2013 at 9:32 PM
[Solved] I am working with new DG. I want to show a csv file in the DG like I used to be able to do in Winforms. Here is my attempt at it. During debugging I can see the objects(DataRows) filling with data, then get error below and nothing shows. Can anyone see a problem or something I may be missing. Thanks.

_Error: Invalid Binging path 0 in 0.

[Solved]
What it looks like as I check internal code is the binding names cannot be a number - initially I was just assigning the loop variable number.ToString as the column name, using a string solves the issue.

Hope this helps someone else!
' I made this array of column names for dynamic loading
Private colNames() As String = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo", "pp", "qq", "rr", "ss", "tt", "uu", "vv", "ww", "xx", "yy", "zz"}
    csvDs.Tables.Clear()
    Try
      Dim ofd As New OpenFileDialog
      If ofd.ShowDialog Then
        If IO.File.Exists(ofd.File.FullName) Then
          csvDs.Tables.Add(csvDt)
          Using fs As IO.FileStream = ofd.File.OpenRead
            Using sr As New IO.StreamReader(fs)
              Dim i As Integer
              While Not sr.Peek = -1
                If i = 0 Then
                  Dim cols = sr.ReadLine.Split(","c)
                  For ii As Integer = 0 To cols.Count - 1
                    'this 
                    Dim col As New BindableDataGrid.Data.DataColumn(colNames(ii))
                    'instead of 
                    Dim col As New BindableDataGrid.Data.DataColumn(ii.ToString)
                    col.DataType = GetType(System.String)
                    col.Caption = ii.ToString
                    col.ReadOnly = True
                    col.AllowReorder = False
                    col.AllowResize = False
                    col.AllowSort = False
                    csvDt.Columns.Add(col)
                  Next
                  Dim row As New BindableDataGrid.Data.DataRow
                  For _i As Integer = 0 To cols.Count - 1
                    row(colNames(_i)) = cols(_i)
                  Next
                  csvDt.Rows.Add(row)
                Else
                  Dim cols = sr.ReadLine.Split(","c)
                  Dim row As New BindableDataGrid.Data.DataRow
                  For _i As Integer = 0 To cols.Count - 1
                    row(colNames(_i)) = cols(_i)
                  Next
                  csvDt.Rows.Add(row)
                End If
                i += 1
              End While
            End Using
          End Using
          dgStaff.DataSource = csvDs
          dgStaff.DataMember = "csvTable"
          dgStaff.DataBind()
        End If
      End If
    Catch ex As Exception
      MessageBox.Show(ex.ToString)
    End Try