R
Ruffin Bailey
I'm getting a:
Data cannot be read from a DataGrid which is not bound to a DataTable.
.... exception when I try the following code:
Private Sub testSub(ByVal intCol As Integer, ByVal dgIn As
DataGrid)
Dim dtTemp As DataTable
Try
dtTemp = CType(dgIn.DataSource, DataTable)
Console.WriteLine(dtTemp.Rows(0).Item(0)) ' works, no
problem
' TODO: ERROR HERE
Console.WriteLine(dgIn.BindingContext(dgIn.DataSource, _
dgIn.DataMember).Count)
' This still works (if you comment out the line above)
Console.WriteLine(dtTemp.Rows(0).Item(0))
' But then you get an error here too
Console.WriteLine(dgIn(i, col).ToString)
Catch ex As Exception
mdlErr.errp("mdlGridUtils.autoSizeCol", ex, _
mdlErr.ERR_TYPES.THROW_EXCEPTION)
End Try
End Sub
I thought if "CType(dgIn.DataSource, DataTable)" gave me something,
that means my DataGrid has to have been bound to a DataTable, by
definition. ?? Fwiw, earlier in the code, dgIn.DataSource is set
equal to a DataTable, but I don't think that matters here -- if the
first cast works, this error shouldn't happen, afaict. As I say, when
I write out dtTemp's first row/first col val to the Console that I've
pulled out with the "CType(dgIn.DataSource, DataTable)" bit, I get a
valid value.
intCol = 0 when I'm testing, fwiw.
What am I missing about DataGrids?
Thanks,
Ruffin Bailey
Data cannot be read from a DataGrid which is not bound to a DataTable.
.... exception when I try the following code:
Private Sub testSub(ByVal intCol As Integer, ByVal dgIn As
DataGrid)
Dim dtTemp As DataTable
Try
dtTemp = CType(dgIn.DataSource, DataTable)
Console.WriteLine(dtTemp.Rows(0).Item(0)) ' works, no
problem
' TODO: ERROR HERE
Console.WriteLine(dgIn.BindingContext(dgIn.DataSource, _
dgIn.DataMember).Count)
' This still works (if you comment out the line above)
Console.WriteLine(dtTemp.Rows(0).Item(0))
' But then you get an error here too
Console.WriteLine(dgIn(i, col).ToString)
Catch ex As Exception
mdlErr.errp("mdlGridUtils.autoSizeCol", ex, _
mdlErr.ERR_TYPES.THROW_EXCEPTION)
End Try
End Sub
I thought if "CType(dgIn.DataSource, DataTable)" gave me something,
that means my DataGrid has to have been bound to a DataTable, by
definition. ?? Fwiw, earlier in the code, dgIn.DataSource is set
equal to a DataTable, but I don't think that matters here -- if the
first cast works, this error shouldn't happen, afaict. As I say, when
I write out dtTemp's first row/first col val to the Console that I've
pulled out with the "CType(dgIn.DataSource, DataTable)" bit, I get a
valid value.
intCol = 0 when I'm testing, fwiw.
What am I missing about DataGrids?
Thanks,
Ruffin Bailey