Background: I'm a little confused on the attributes on a BO's "data" or "field" properties.
I'm trying to use a PropertyGrid (System.Windows.Forms.PropertyGrid) to display the data from a BO. I've used them before to show properties on other objects and had no problems but when the object is a StrataFrame BO attribute related stuff isn't behaving the same.
If anyone reading isn't familiar with the PropertyGrid: you can set it's SelectedObject property to an object and it will display all that object's properties and their values just like the Properties Window in Visual Studio does. Also, if you give a property a DisplayName attribute, the PropertyGrid is supposed to show that on the left hand side of the grid instead of the property's actual name. If you don't give it a DisplayName attribute, it shows the property's name instead.
Similarly, if you give it a Description attribute, that will show at the bottom of the PropertyGrid if you have the grid showing descriptions. And you can set a Category attribute and it will groups properties with the same category, again like Vis. Studio does (Appearance, Behavior, Layout, etc.).
Also, part of the equation is that the PropertyGrid normally only shows properties that have the Browsable attribute set to true. Ones with Browsable set to False don't show up in the grid.
For instances of other classes I've pointed the PropertyGrid at all the above works as described.
If I set a grid's SelectedObject to a StrataFrame BO:1) Good (but confusing): It shows just the "data" properties (the ones that correspond to fields in the database) and not the ones that we use at design time in V.Studio to set the BO instance up. This is great: those are the only fields I wanted to show the user anyway so this is fine. But I am confused on why they show though since in the code in the partial class generated by the BO mapper has all those set to Browsable = False (along with all the other properties of the BO that I didn't want to see).
2) Good: It shows those data properties' values fine on the right side of the grid and if I go into edit mode and I edit values they save fine so it acts like it's "bound". (not sure this can be considered true binding but my point is it acts how bound controls do and for what I'm trying to do that's a good thing) (Since it's not a SF control it isn't enabling and disabling accoring to the 'edit mode' right now but I should be able to get that working.)
3) Bad: If I add DisplayName and/or Description attributes to my data properties, it still just shows the field name and no description. For now I was just doing this hardcoded in the partial class after generating it and being careful to not regenerate it (and blow my stuff away). It always just shows the field's name (cust_Address1, cust_LastName, etc.) instead of the DisplayName attribute values I give it. It also doesn't put them in categories if I add Category attributes: just puts them all under Misc which is what the PropertyGrid does for properties with no category. And it won't display the Description at the bottom.
Down below I have steps to reproduce this in one of the SF tutorials. It has 2 grids: the grid pointing at my class works fine as far as the attributes but the BO one seems to ignore all the attributes.
Is it really accessing a separate parallel object at runtime? Maybe an object that has just the data properties and/or has different attributes like Browsable = True for just those and doesn't have the other attributes that were set in the BO's partial?
If I suspend at runtime and look at the instance of the BO that was put on the form, it has the data properties and their values and they change as it navigates, etc. and if I look at the attributes on the properties, everything still has Browsable = False (including the data ones that do show in the grid) and my DisplayName, Description, and Category attributes and values for them that I added are still there. (I did this using reflection, GetProperties(), GetCustomAttributes(), etc.: See attachment "reflection button click.txt" for code that I stuck in a button to look at this but it's not in my steps to reproduce. If you use that you'll need to add "Imports System.Reflection".)
Also at runtime,
me.CustomersBO1.Equals(me.grdCustomer.SelectedObject)
evaluates to True so it seems like the propertygrid is really pointing at the BO that I was looking at in the paragraph above that had the right attributes so I'm stumped.
Steps to reproduce:1) Make a copy of the directory "Tutorial_WinVB_8" (that's eight) (which is probably in "C:\Program Files\MicroFour\StrataFrame\VB.NET Samples\WinForm Tutorial\")
2) In the copied folder rename the file "CustomerMaintenance.vb" and replace it with the version that is attached to this post (fix the extension of the attachment).
This just adds on to the Customer Maintenance screen: a couple Imports statements, defines a new class with 3 properties and some attributes on each, instantiates 2 PropertyGrids and 1 of the new class and hooks them all up.
3) Open the "Tutorial_WinVB.sln" solution in the copied folder in Visual Studio
4) Edit "CustomersBO.Designer.vb": in the "Field Properties" region, find the lastname section which should look something like this except it doesn't have the DisplayName and Category attributes and the Description is still cust_LastName. Replace it with the stuff below to add those 1st 2 and make description different from cust_LastName (only the attribute part between the < > is different):
'''
''' cust_LastName
'''
'''
BusinessFieldDisplayInEditor(), _
Description("Last Name Description"), _
DisplayName("Last Name Display Name"), _
Category("Name"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Property [cust_LastName]() As System.String
Get
Return CType(Me.CurrentRow.Item("cust_LastName"), System.String)
End Get
Set(ByVal value As System.String)
Me.CurrentRow.Item("cust_LastName") = value
End Set
End Property
5) Take a quick look at the class defined at the bottom of "CustomerMaintenance.vb" and notice it's 3 props and the Browsable, DisplayName, Description, and Category attributes (category only on 1)
6) Run it. Notice how the display name on the last name in the BO grid on the left stayed cust_LastName but the String1, String2, and String3 in the right grid show the DisplayNames I set in their attributes And if you Click on the cust_lastname in the lower left grid it's description doesn't show but if you click any of the right grid's properties you see their descriptions in the bottom. (And the categories worked on the right but not for the left one.)
I've tried setting Browsable to True, I've tried the code in both Visual Studio 2005 and 2008, and tried other stuff and looked at lots of stuff but nothing has worked or given me an idea of what is going on.
Sorry this was a bit long...
Any thoughts/help?
Thanks,
Andy