Here is the code that worked previously and is throwing an exception now. Its purpose is to set the column header based on a datasets caption property. I think I went from Q1 2010 to current. I will also show some strange debug watch results.
The exception is being caught when trying to evaluate:
Here are the watch results on one of the passes. The field xx_tablename is expected. I am setting field = e.Column.HeaderText early on.
If I hard code variable field to "xx_tablename" in the beginning it does not error out and I get the result I want.
Private
Sub
RadGrid_ColumnCreated(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridColumnCreatedEventArgs)
Handles
RadGrid.ColumnCreated
Dim
field
As
String
Try
field = e.Column.HeaderText
If
Not
field =
Nothing
And
field <>
""
Then
If
DataSet.Tables(TableName).Columns(field).ColumnName =
"ID"
Then
'e.Column.Display = False ' this causes some strange formatting problems
ElseIf
DataSet.Tables(TableName).Columns(field).Caption() = _
DataSet.Tables(TableName).Columns(field).ColumnName
Then
e.Column.Visible =
False
Else
e.Column.HeaderText = DataSet.Tables(TableName).Columns(field).Caption()
e.Column.HeaderStyle.Wrap =
False
End
If
End
If
Catch
ex
As
Exception
End
Try
End
Sub
The exception is being caught when trying to evaluate:
DataSet.Tables(TableName).Columns(field).ColumnName
Here are the watch results on one of the passes. The field xx_tablename is expected. I am setting field = e.Column.HeaderText early on.
DataSet.Tables(TableName).Columns(0).ColumnName | xx_tablename | String |
e.Column.HeaderText | xx_ tablename | String |
DataSet.Tables(TableName).Columns("xx_tablename").ColumnName | xx_tablename | String |
field | xx_ tablename | String |
DataSet.Tables(TableName).Columns(field).ColumnName | Referenced object 'Item' has a value of 'Nothing'. | |
ex.message | Object reference not set to an instance of an object. | String |
If I hard code variable field to "xx_tablename" in the beginning it does not error out and I get the result I want.