Adding designer support to a custom tree control

G

Guest

Hey all... I posted this in the vs.net ide group too, but people are not answering, so I figured that it might be more appropriate here. I'm not sure if I'm adding a designer to my code properly. I'm only adding it to the tree node, where each custom tree node is then added to a normal tree control

I'm trying to get an add-in to interact with the property window in VS.Net. Basically, I created a tool window containing a custom tree control. When the user clicks on a tree node, I want certain properties to show up in the property window. My understanding is that I need to create a designer for the component, and override the prefilterproperties method. The problem right now is that when I use clicks a node, I get no update to the property window. Do I need to hook an event to notify the property window that the tree node was clicked? Documentation on this seems sort of sparse, so any help would greatly be appreciated.

Also, I've seen this article: http://www.msdn.microsoft.com/libra...ibrary/en-us/dndotnet/html/custdsgnrdotnet.as

Thank

Ji

Here are some snippets of what I already have

[Designer(typeof(MyTreeNodeDesigner))]
public class MyTreeNode : TreeNod

private XmlNode _xmlNode
private string _type = String.Empty

/// <summary
/// Represents the xml fragment for this My objec
/// </summary
public XmlNode XmlNod

get { return this._xmlNode;
set { this._xmlNode = value;


/// <summary
/// Represents the <see cref="IMyObject"/> type nam
/// </summary
public string Typ

get { return this._type;
set { this._type = value;


public MyTreeNode(string nodeName

this.Text = nodeName


public MyTreeNode(string nodeName, string name

this.Text = nodeName + " - '" + name + "'"



public class MyTreeNodeDesigner : System.Windows.Forms.Design.ControlDesigne

bool locked

private bool Locked

get

return locked

set

locked = value;



public MyTreeNodeDesigner(



protected override void PreFilterProperties(IDictionary properties

base.PreFilterProperties(properties)

properties["Locked"] = TypeDescriptor.CreateProperty
typeof(MyTreeNode),
"Locked",
typeof(bool), new Attribute[0])
 
J

Jeffrey Tan[MSFT]

Hi Jim,

Thank you for posting in the community!

Based on my understanding, you want to write a customized TreeView control,
and you want to add some design-time support for it. That is, you want the
TreeNodes in the TreeView to be selected and modify properties from
Property Browser.

=======================================================
I think this is a much complex work, and need a lots work to do.

In .Net Windows Form designer, TreeNode is container in the TreeView
control, and it design-time behavior is first be managed by the TreeView
control. So to get what you want, you should first write the designer for
the TreeView control.

The TreeView control actually use an INTERNAL
"TreeViewControlDesigner"(This name is bogus) for its design-time
behaviro(Not the default ControlDesigner). Because this designer is
internal, you must write a customized designer for your TreeView.

The code below will allow you to expand and collapse your TreeView
control.(This is not allowed for ControlDesigner class's default behaviro)

[Designer(typeof(MyTreeViewDesigner))]
public class MyTreeView : System.Windows.Forms.TreeView
{
}

public class MyTreeViewDesigner: System.Windows.Forms.Design.ControlDesigner
{
protected override bool GetHitTest(Point point)
{
return true;
}
}

And also, you must provide your customized designer for the TreeNode class.
Unfortunately, TreeNode is not a *control*(Does not inherited from
System.Windows.Forms.Control), and it does not implement IComponent
interface. So you can not apply ControlDesigner(More detailed,
ComponentDesigner) on it.

So you must implement the IComponent interface for the your TreeNode, then
user root designer's to add the TreeNode to the VS.net designer.

Till now, you will see how many thing you need to do to get this done(What
I stated may be not the whole work you should do, extra work may need). I
strongly recommanded that you use other way to workaround.

I think you may use CollectionEditor for TreeView's Nodes property. And
modify the TreeNode's property in the Editor.

===========================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Jim,

Thanks very much for your feedback.

I have reviewed your post, I will spend sometime in review that articles.

I will reply to you ASAP after research.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Jim,

After quick reviewing the article for the first time, I found some of its
features are the run-time property editing.

Do you want to edit your treenode at run-time or design-time?

If you want to get this done at run-time, you only need to use PropertyGrid
control on your Form.

For an article about how to use Property Grid in your WinForm application,
please refer to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/usingpropgrid.asp

If you need the runtime feature, please feel free to feedback to me

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hey Jeffrey

I'll need to make use of the run-time property editing. I'll have a collection of unique attributes that will need to be available to the property grid in VS.Net. I will not know what those attributes names or values are until run-time, but I would like each of them to show up in the grid. Also, I will not be able to setup properties for each of the attributes, so I am looking for a way to programatically add designer support at run-time. For example, rather than being able to add specific classes to my project, like this

public class MyPropertie

[CategoryAttribute("Attributes")
DefaultValueAttribute("SomeValue")]
public string PropertyNam
{ get { return this.value;
set { this.value = value;



Ideally, I want to be able to dynamically add PropertyName with a default value of "SomeValue" and assigned to category "Attributes" to the propertygrid at run-time

To use an example, I want to take an XmlNode and display each of the attributes for that node in the property grid. Each xml attribute would display in the grid as the attribute name and have it's associated value. Since I don't know what node attributes will be present, I'll need to add the properties to the grid dynamically

Also, since the property grid control is outside of my application, I don't believe that I'll have control over setting the SelectedObject property for it

I hope this sort of clears up what I'm looking to accomplish

Thanks for all your help and patience with this

Jim
 
J

Jeffrey Tan[MSFT]

Hi Jim,

Thanks very much for your feedback.

For your feedback, I understand that you want the run-time property editing
function.

But I am not fully understand your description, I think I will clarify some
concept for you and ask some further information from you.

======================================================
First, PropertyGrid is a .Net WinForm control, which can be used on the
Windows Form application at run-time(As a property designe support). While
in VS.net IDE, PropertyBrowser is a design-time browser for the designer
controls. For your reqest, I think you can make use of PropertyGrid control
in your application, but why you say: " property grid control is outside of
my application, I don't believe that I'll have control over setting the
SelectedObject property for it."?

Second, in your first paragraph's description "I will not know what those
attributes names or values are until run-time", what does *attribute* mean?
Does it mean Property?
Or it is really the attributes of the property?(Such as the
ReadOnlyAttribute, CategoryAttribute).

For "I will not be able to setup properties for each of the attributes",
what does "property for the attributes" mean? Does it mean the value of
these attributes?(Such as true or false for ReadOnlyAttribute, the category
string value for the CategoryAttribute)

Please clarify these things for me, so that I can help you better.

=====================================================
I will wait for your further feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Jim,

Thanks very much for your feedback.

I have reviewed your post, I see your concern.

I have got some clue about this issue, but I will clean up my mind and
provide your more integrated information for it.
I will reply to you ASAP.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Jim,

I think you want to read the xml nodes in the xml file, then display their
attributes in the propertygrid dynamicly.

========================================
Actually, to get this done you can create a class which implement the
ICustomTypeDescriptor interface.

You should create your own propertydescriptor class(Inherit the
PropertyGrid class), then in ICustomTypeDescriptor.GetProperties() method,
you can create your own PropertyDescriptorCollection with your
propertydescriptor.

Do like this:

public PropertyDescriptorCollection
GetProperties() {
PropertyDescriptor[] pd = new
PropertyDescriptor[node.Attributes.Count];
for (int i = 0; i < node.Attributes.Count; i++)
pd = new
MyPropertyDescriptor(node.Attributes.Name);
return new PropertyDescriptorCollection(pd);
}
}

Note: the node is the xmlnode of your xml file.

You also can add various attribute on your property at runtime through this
interface.

There is an article "Bending the .NET PropertyGrid to Your Will" teaches
you how to Implement ICustomTypeDescriptor interface and do customize
property display, please refer to:
http://www.codeproject.com/cs/miscctrl/bending_property.asp

Also, these 2 articles may help you:
http://www.codeproject.com/cs/miscctrl/customizingcollectiondata.asp?target=
ICustomTypeDescriptor
http://www.codeproject.com/cs/miscctrl/globalizedpropertygrid.asp?target=ICu
stomTypeDescriptor

=============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Ok, I'll give that a shot and let you know if I run into any issues.

Thanks Jeffrey!

Jim
 
J

Jeffrey Tan[MSFT]

Hi Jim,

Thanks very much for your feedback.

I will wait for your feedback, if there is still something unclear, please
feel free to post, I will help you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top