Hi All,

I'm using VB.NET and want to create a datagridview showing the value of a 
child property (Datapropertyname = User.Username).
I found following code:

Private Function EvaluateValue(ByRef myObj As Object, ByRef myProp As String) 
As String
  Dim Ret As String = ""
  Dim Props As System.Reflection.PropertyInfo()
  Dim PropA As System.Reflection.PropertyInfo
  Dim ObjA As Object

  If myProp.Contains(".") Then

   myProp = myProp.Substring(0, myProp.IndexOf("."))
   Props = myObj.GetType().GetProperties()

   For Each PropA In Props

    ObjA = PropA.GetValue(myObj, New Object() {})
    If ObjA.GetType().Name = myProp Then

     Ret = EvaluateValue(ObjA, myProp.Substring(myProp.IndexOf(".") + 1))
     Exit For

    End If

   Next

  Else

   PropA = myObj.GetType().GetProperty(myProp)
   Ret = PropA.GetValue(myObj, New Object() {}).ToString()

  End If

  Return Ret
 End Function


But when I am using this with following code:

Private Sub List_CellFormatting(sender As Object, e As 
DataGridViewCellFormattingEventArgs) Handles List.CellFormatting
        Dim Grid As DataGridView = CType(sender, DataGridView)
        e.Value = Func.EvaluateValue(Grid.Rows(e.RowIndex).DataBoundItem, 
Grid.Columns(e.ColumnIndex).DataPropertyName)
    End Sub

I get a null reference on ObjA.

Anyone experienced with this? Or has someone another way to get the value of 
the child property in the datagrid?


Benjamin



-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to