index > Visual Studio Team System - Domain-Specific Language Tools > How to update PropertyGrid after changing type

How to update PropertyGrid after changing type


Hi all,

Our model allows to change the type of an element using the property grid. The element type changes succesfully, but the propertgrid is not updated accordingly.
When another element is selected and then the changed element, then the propertygrid displays the correct properties.

How can I dynamically update the property grid after changed the element's type?

Kind regards,
Ronald

RonaldK

Hi Ronald,

What do you mean when you say you change the type of an element? Do you mean you change the model element that a shape represents?

Thanks,
George Mathew
DSL Tools Team

George Mathew

Hi George,

We have a DSL that contains model elements called AfdAttribute. Derived from AfdAttribute are AfdTextAttribute, AfdNumberAttribute etc. Attributes have no shape, because they are displayed as a melCollection (Model ELementCollection ?) of an Entity shape.

After adding an AfdAttribute to an Entity, the user can change from AfdTextAttribute to AfdNumberAttribute and v.v.. AfdTextAttrute and AfdNumberAttribute have differtent properties, which we want to be displayed in the PropertyGrid correspondingly.

I hope I used the correct terms.

Regards,
Ronald

RonaldK

Hi Ronald,

Thanks for the eplanation. You say "After adding an AfdAttribute to an Entity, the user can change from AfdTextAttribute to AfdNumberAttribute and v.v..". How does the user change from AfdTextAttribute to AfdNumberAttribute? I'm assuming you are showing the AfdAttributes as a compartment within an Entity.

Thanks,
George Mathew
DSL Tools Team

George Mathew

Hi George,

You are right, I'm showing the attributes as a compartment within an Entity.

An Entity provides some kind of context. Within that context only certain values (more concrete: mappings) are allowed. After adding a AfdAttribute to an Entity the user can set properties of the AfdAttribute, a.o. the property Mapping. Using a UITypeConverter I display a dropdown showing only allowed Mappings within the context of the Entity. The user selects a Mapping from the dropdown and on the dropdown click event I read the selected Mapping. A mapping has a type, e.g. string, int etc. Using the type of the selected Mapping I can derive the corresponding AfdAttribute, e.g. AfdTextAttribute for a string type Mapping. Then I create the corresponding subtype of AfdAttribute and replace the current AfdAttribute with the newly created attribute.

The last part in code (AfdPropertyDescriptor is the class representing a mapping):
private void SetAttribute(System.ComponentModel.ITypeDescriptorContext context, AfdPropertyDescriptor propDesc)
{
ElementPropertyDescriptor descriptor = context.PropertyDescriptor as ElementPropertyDescriptor;
ModelElement element = descriptor.ModelElement;
AfdEntity container = ((AfdAttribute)element).AfdAttributeContainer;
using (Transaction t = container.Store.TransactionManager.BeginTransaction("Change AfdAttribute"))
{
AfdAttribute atttribute = CreateAttribute(container.Store, propDesc, (AfdAttribute)element);
int index = container.AfdAttributes.IndexOf((AfdAttribute)element);
container.AfdAttributes.ReplaceAt(index, atttribute);
t.Commit();
}
}

After replacing the AfdAttribute I would like to update the propertygrid to display the properties of the new AfdAttribute type, something like: propertyGrid.SelectedObject = attribute.

Regards,
Ronald

RonaldK

Hi Ronald,

Does George's reply to your other thread at

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=306422&SiteID=1

answer this? i.e. Resetting the selection to refresh the grid?




Gareth Jones - Developer - DSL Tools & Software Factories Platform [MSFT]
GarethJ MSFT

I know that it is kind of a hack but you can do:

propertyGrid1.Hide();
propertyGrid1.Show();

I haven't been able to figure it out but somehow you have to rebind all the controls and repainting the propertygrid causes this to happen.

Hope it helps.

Michael Bartlett
reply 7

You can use google to search for other answers

 

More Articles

Opening an existing DSL in a fresh install of VS
No more RedistInstallDir registry value in Feb. 2006 DSLToolsRedi...
Show more than one Property in a Compartment
where can ? find info about DSL?
protected internal
Experimental UI - show and hide shapes and connectors
Fixed diagram layout
Name of EventHandler called when Compartment item is selected?
Referencing Domain Classes from Domain Properties
Non string name domain properties
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

cannot drag & drop shape from toolbox
some question In DSL Tools
Programmatically creating diagrams
How to implement Rules in DSL
Can i use the DSL Diagram components in …
Resources: Domain Specific Language (DSL…
CTC Problem
Package Load Failure - ...TextTemplating…
Adding files generated with text templat…
February CTP of DSL Tools is live in the…
How to update PropertyGrid after changin…
Rules in DSL Tools V1
Comments and CommentShapes
March CTP DSL uninstall / VS (RC) issue
use case template dropped?

Hot Articles

Connectors connecting to connectors
Reading and writing models in June relea…
How to move shapes within diagram progra…
Checkbox list as property type which is …
November DSL toolkit: how to add command…
How to access to the shape connectors by…
Add shapes and connectors to diagram pro…
my feedback about dsl
Why the f$%^&* does the DSL tools as…
DSL Tools Team HIRING in Cambridge, UK
How adequate-rich or suffitient-complete…
How to access the Session in subdomain?
Validation when dropping an element on t…
Change a connector's from and to endpoin…
DSL Designer architecture

Recommend Articles

CMDS: Missing package guid for commands …
Cannot create a new Store
Workaround: Recovering invalid model fil…
Category feedback
Unable to Replace Old Files by New ones
VS Host Assembly Resolving and parameter…
Error Creating DSL Designer Project
ZOrder
Nesting relationships, can't link to Ima…
Problem starting new DSL-project
Validation / Rejecting a change from a C…
DSL Tools V1 Released
academic distribution of a DSL
Minor gotcha in the Adding a Compartment…
where can ? find info about DSL?