Choosing a property of type businesslayer based on the name as a string


Author
Message
Charles R Hankey
Charles R Hankey
StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)
Group: Forum Members
Posts: 524, Visits: 30K
This is one of those things I do instinctively in Fox with Eval() or & and don't quite have the hang of yet in .NET



I have a number of private properties of type businesslayer



_Endorsements

_Premises

_GL

_Propmaster





I get a name ( but getting the displayvalue of an enum BOName ) of a business object.



The properties are named _



Now I want to look at the count of the BO based on the string which have representing



Dim varname as String = "_" & MicroFour.StrataFrame.Tools.Common.GetEnumDisplayValue(bo.BOName)



Lets say varname = "PROPMASTER"



Now I want to get the count of whatever BO is in the property which is in the string varname



i.e. Propmaster.count





Fumbling with syntax here. Appreciate any guidance.



TIA

Reply
Charles R Hankey
Charles R Hankey
StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Michel Fournier of the UT was kind enough to lay this function on me which works like a dream. I'll also post it in contributed samples. Very slick and works beautifully :



' Return a reference to a control by the use of its name

' expO1 Form

' expC1 Name of the control

Public Shared Function FindControlByFieldName(ByVal loForm As System.Windows.Forms.Form, ByVal tcProperty As String) As Object

Dim loFieldInfo As System.Reflection.FieldInfo = Nothing

Dim loObject As Object = Nothing

Dim loPropertyInfo As System.Reflection.PropertyInfo = Nothing

Dim loType As System.Type = Nothing



' Get the form type

loType = loForm.GetType()



' Get the property info

loPropertyInfo = loType.GetProperty(tcProperty, System.Reflection.BindingFlags.Public Or _

System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance Or _

System.Reflection.BindingFlags.DeclaredOnly)



' If the property info is known as an object

If Not loPropertyInfo Is Nothing Then

Return loPropertyInfo.GetValue(loForm, Nothing)

End If



' Get the field info

loFieldInfo = loType.GetField(tcProperty, System.Reflection.BindingFlags.Public Or _

System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance Or _

System.Reflection.BindingFlags.DeclaredOnly)



' If the field info is nothing

If loFieldInfo Is Nothing Then

Return Nothing

End If



' Get the field object

loObject = loFieldInfo.GetValue(loForm)



Return loObject

End Function





Now this is all the code I need to accomplish what I want





Dim childname As String = "_" & MicroFour.StrataFrame.Tools.Common.GetEnumDisplayValue(bo.SpilloverGrid)



Dim childbo As BaseBO = CType(FindControlByFieldName(Me, childname), BaseBO)



dim records as Int32 = childbo.count







BigGrin

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search