Wednesday, March 28, 2012

PropertyGrid and SMO objects

With Visual studio 2005 I've mapped my SMO objects and a new PropertyGrid control, everything works fine (a lot thanks to Microsoft VS 2005 team for this wonderfull and power control).

However I have two problems :

1. if I make some change in my PropertyGrid how to apply these changes to related object in my database ?

2. If my user dosn't have enough permission to change my DB objects how to turn PropertyGrid to ReadOnly mode ? ReadOnly property doesn't exist and set Enabled property to false doesn't work since the user cannot navigate through properties

Any help ?

Thank youYou'll need to add an Apply button (or some other control) on your form to give you an event for committing changes. For many SMO classes, you'll be able to commit changes by simply calling the Alter() method on the object that is being displayed in the PropertyGrid.

One way to get the read-only behavior you are looking for would be to create a wrapper class for the SMO class that only exposes property getters for the SMO class properties. If there is only a property getter, the PropertyGrid makes the corresponding cell read-only. So if the user has sufficient privileges, set the SelectedObject property to the SMO object directly, otherwise set the SelectedObject to your read-only wrapper around the SMO object.|||

better put button on propertygrid...

create your own pg and on New()

.......

Dim f As ToolStrip = Me.TOOLSTRIP

Dim n As New ToolStripButton

n.Text = "ADD"

AddHandler n.Click, AddressOf cADD

f.Items.Add(n)

Dim nD As New ToolStripButton

nD.Text = "Save"

AddHandler nD.Click, AddressOf cSave

f.Items.Add(nD)

No comments:

Post a Comment