求:VB.NET转换为C#的一段代码:(
Private Sub ItemDataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim cell As TableCell = CType(sender, TableCell)
Dim DGI As DataGridItem = CType(cell.NamingContainer, DataGridItem)
Try
cell.Text = DGI.DataItem(DataField)
Catch RangeEx As IndexOutOfRangeException
Throw New Exception("Specified DataField was not found.")
Catch OtherEx As Exception
Throw New Exception(OtherEx.InnerException.ToString)
End Try
End Sub
注:Public DataField As String。
关键是
cell.Text = DGI.DataItem(DataField)
偶转换为
DataGridItem DGI =(DataGridItem)cell.NamingContainer;
cell.Text =DGI.DataItem[DataField];
时总报错~~:无法将带 [] 的索引应用于“object”类型的表达式