I have a VS 2010 Excel 2007 Workbook application. I have a ListObject that is bound to an object data source via a binding source. I want to be able to determine what property of my object any given ListColumn obect in my ListObject's ListColumns collection is bound to. In the example below I use the column name to find the column that is bound to the "Field1" property. However, in my situation, the column name can be different from the property Name. There is no DataMember, DataPropertyName, or similar property on a ListColumn object, how do I figure out what column is bound to what property?
Given the class and ListObject below, I want to be able to use the following code:
return FindColumn(MyDataListObject, "Property1")
Public Class MyData
Public Property Field1 As String
Public Property Field2 As Date
End Class
Public Function FindColumn(ByVal listObject As ListObject,
ByVal propertyName As String) As ListColumn
For Each col As ListColumn In listObject.ListColumns
If col.Name = propertyName Then
Return col
End If
Next
Return Nothing
End Function