Confusion on BO data/field property attributes


Author
Message
jandyn
jandyn
StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)
Group: Forum Members
Posts: 5, Visits: 37
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
Attachments
CustomerMaintenance.vb.txt (162 views, 4.00 KB)
reflection button click.txt (132 views, 1.00 KB)
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
I really don't know how to respond to this post but I didn't want to leave it out here without a comment.  Here is the deal, most of what you are trying to do has nothing to do with StrataFrame but rather standard .NET and how type editors and designers work with the property grid.

For me to respond to this is more of a training session and would take a fair amount of time which is not the intent of this forum.  I don't want to leaving you hanging here, so I set this up and it works just fine.  Here may be a few pointers. 

First of all, here is the property grid with the exposed custom property of the BO:

Here is the defined property on the BO:

<Browsable(True), _
BusinessFieldDisplayInEditor(), _
Description("My Custom Property"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
<DisplayName("My Custom Property")> _
Public ReadOnly Property cust_MyProperty() As System.String
Get
    Return "Something Else"
End Get
End Property

And here is the property descriptor defined in the GetCustomBindablePropertyDescriptors:

Protected Overrides Function GetCustomBindablePropertyDescriptors() As MicroFour.StrataFrame.Business.FieldPropertyDescriptor()
Return New MicroFour.StrataFrame.Business.FieldPropertyDescriptor() { _
New ReflectionPropertyDescriptor("cust_MyProperty", GetType(CustomersBO)) _
}
End Function

You can see that I set the Browsable to True so that it would show up in the property grid, but at this point it is all .NET and so any attributes that you want to tweak or apply are going to be well documented in the .NET docs and samples on the web.

jandyn
jandyn
StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)
Group: Forum Members
Posts: 5, Visits: 37
I realize a good chunk of it is just plain .NET BUT based on the attributes I see being set, the SF BO behaves differently at runtime which is where my confusion is.



That's why I made a point of saying I've done this with other objects and in those cases it behaves just the way the docs say it should, both at designtime and runtime (runtime being key: see #2 below).



2 things:

1) I was just referring to just the properties that are bound to the data source behind the BO, not a custom property. I tried a custom prop like you show too at some point but my main need is the data field properties. In the case of the 'SF tutorial step 8' copy I referred to above, that would mean the fields like cust_Address1, cust_Address2, cust_City, cust_Company, etc.



2) From your screenshot, it looks like you are in design-time still. My problem is at runtime. I can add the custom prop you show too and I also see it at design-time BUT please run it like I mention in step 6 and look at what properties are showing in the grid then and what names are shown for them.



When I run it, just the data bound properties are there (good) but the attributes that should control if/how they display (browsable, category, displayname, description, etc.) are being ignored. See the attached picture.

I also notice that the custom property I added by copying your code above doesn't show at runtime either but maybe I still need a bit more 'plumbing' for that. That could be a problem for some situations for people but for what I'm working on now I just need the data bound ones.





IF it is still the same object the PropertyGrid is pointing at at runtime, from what I see in the MS docs some of the following look like they would affect this stuff but I don't see that the SF source code does anything different (from what I can tell).

ICustomTypeDescriptor, GetAttributes, GetProperties: these look right (again, from what I can tell)

PreFilterAttributes, PostFilterAttributes, PreFilterProperties, PostFilterProperties: don't see these implemented so that seems ok...



Thanks,

Andy



Attachments
2grids.png (133 views, 38.00 KB)
jandyn
jandyn
StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)
Group: Forum Members
Posts: 5, Visits: 37
Any followup Trent?

Did you run it?
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
No, since my last post I have not looked at this.  I will try and set this up later or you can supply a sample to speed the process.  This really has more to do with .NET and the PropertyGrid versus SF.  I would imagine that you are fighint the property descriptors (used for reflection) in this case, but until I set it up again (the first sample I created to post for you is gone) I won't know.  Also, when I setup that first sample it all worked as it should, so there may be something environmental here.  So really the best thing may be that you create a small sample reproducing the problem and I will look at it from that perspective.
jandyn
jandyn
StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)
Group: Forum Members
Posts: 5, Visits: 37
I supplied a sample in my first post above: see the 'Steps to reproduce' which shows it by making a couple small changes to the SF installed tutorial using the version at step 8 (but see my correction below).



The forum keeps taking out a line from the code I say to paste in. It should

have < browsable(False), _ as the first line after the comment block but must think it's a HTML tag.



'''

''' 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






The steps only take a couple minutes.



It creates the prop grids in code so you won't see the stuff you did in design time but I've done it in the designer like you did and can confirm it looks that way at design time BUT at run time doing it in code or the designer gets the same results I'm talking about.

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
That's not exactly what I had in mind, but OK.  When I was referring to a sample I meant that all I had to do was download a solution, etc. Run it and take a look.
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