TypeConverter for custom collections

scottyrs

Newcomer
Joined
Nov 12, 2004
Messages
5
My application uses a Treeview to represent the hierarchy of an underlying object model. Users can add / delete nodes in the tree and use a PropertyGrid for managing the object properties of a selected node's TAG data (an object in the model). The treeview provides a convenient way to navigate (up and down) the objects and the propertygrid a nice way to categorize/modify the properties. It works great when staying within the object hierarchy, but when trying to get to an object in one tree branch from another branch outside, I can't quite get it.

As example:
I have two Nodes in the tree in different branches:

NodeOne.TAG is a collection of objects that the user can add items to.

NodeTwo.Tag is an object that has a property type of items in the first Node.tag (collection).

My issue is trying to create a TypeConverter for NodeTwo.Tag.property that can:

-Create a StandardValuesCollection based on the items in the collection to show in the dropdown for the property.

-Update the property with the value from selected object that is referenced in the list.

I can create a list of names from the collection for the StandardValuesCollection in the typeconverter but can I attach to the selected object?

Any feedback is appreciated. Thanks!
 
What type of Collection are you storing in the Tag properties? Bindable controls like the ComboBox can use anything that implements ICollection as its DataSource.......you may not need to create a StandardValuesCollection.

I am not completely clear on what you are getting at but have wrestled with the TreeView quite a bit.....could you post some code?

scottyrs said:
My application uses a Treeview to represent the hierarchy of an underlying object model. Users can add / delete nodes in the tree and use a PropertyGrid for managing the object properties of a selected node's TAG data (an object in the model). The treeview provides a convenient way to navigate (up and down) the objects and the propertygrid a nice way to categorize/modify the properties. It works great when staying within the object hierarchy, but when trying to get to an object in one tree branch from another branch outside, I can't quite get it.

As example:
I have two Nodes in the tree in different branches:

NodeOne.TAG is a collection of objects that the user can add items to.

NodeTwo.Tag is an object that has a property type of items in the first Node.tag (collection).

My issue is trying to create a TypeConverter for NodeTwo.Tag.property that can:

-Create a StandardValuesCollection based on the items in the collection to show in the dropdown for the property.

-Update the property with the value from selected object that is referenced in the list.

I can create a list of names from the collection for the StandardValuesCollection in the typeconverter but can I attach to the selected object?

Any feedback is appreciated. Thanks!
 
RobEmDee said:
What type of Collection are you storing in the Tag properties? Bindable controls like the ComboBox can use anything that implements ICollection as its DataSource.......you may not need to create a StandardValuesCollection.

I am not completely clear on what you are getting at but have wrestled with the TreeView quite a bit.....could you post some code?

Thanks for response. Here is an example of what I am using.

I don't believe the Treeview is the issue but rather it's using the PropertyGrid to edit the properties in the hierarchical object model that it represents. There are a series of classes that inherit Treenode for each of the different objects that can be added to the tree. The tag data for a node references the appropriate object type and may be an object or a collection. You click on a node to show the properties of the object in the node's Tag in a property grid. A property may be a collection but currently I am not implementing UI collection editors in the propertygrid.

I am still examining TypeConverters, although the documentation is not real clear for me yet.

Example:

Code:
'Collection -Managed independently in the tree (i.e Add/Delete/Edit properties)
'Has a PathsNode that inherits TreeNode, as it's U.I.
'Is the tag data for a PathsNode

Public Class Paths 
Inherits CollectionBase 

'Retrieves an item from the collection by index 
    Default Public Property Item(ByVal Index As Integer) As Path 
        Get 
            Return CType(list.Item(Index), Path) 
        End Get 
        Set(ByVal Value As Path) 
            list.Item(Index) = Value 
        End Set 
    End Property 

'Add function 
'Remove function 
'.Etc...... 

end class 


'This is the class for items added to the Paths Collection
'Has it's own Node inherited from TreeNode
'Is type of Tag data for node
public class Path 

  private _Property1 as type 

  public property Property1 as type 
    'get 
    'set 
  end property 

'etc...

end class 


'This is a separate class
'Has a Node that derives from Treenode
'Is Tag data for it's node type
'Another Class 
public class AnotherItem 

  private _AnotherProperty as string 
  private _PathProperty as Path 

  public sub New 

  end sub 

  public property AnotherProperty() as string 

    'get 
    'set 

  End property 

'*****************************************************
'THIS IS THE PROPERTY THAT I WANT TO MANAGE IN PROPERTYGRID!
'HOW TO MAKE THIS SHOW IN THE PROPERTY GRID AS A DROP DOWN 
'TO SELECT FROM ITEMS IN THE PATHS COLLECTION ABOVE AND 
'REFLECT THE OBJECT VALUES.
'ALSO, CANNOT EDIT VALUES OF SELECTED OBJECT HERE

  <CategoryAttribute("Details"), _ 
  TypeConverter(GetType(ExpandableObjectConverterForItem)), _ 
  Browsable(True), _ 
  PropertyOrder(9), _ 
  [ReadOnly](False), _ 
  BindableAttribute(False), _ 
  DesignOnly(False), _ 
  DescriptionAttribute("Path of this Item")> _ 
  public property PathProperty as Path 

    'get 
    'set 

  end property 

end class
 
scotty:
Sorry, but my experience with coding VS is very limited...wish I could help more.
I noticed you have a mix of C# and VB...are you working from an example you downloaded from somewhere? I'd like to check it out.

scottyrs said:
Thanks for response. Here is an example of what I am using.

I don't believe the Treeview is the issue but rather it's using the PropertyGrid to edit the properties in the hierarchical object model that it represents. There are a series of classes that inherit Treenode for each of the different objects that can be added to the tree. The tag data for a node references the appropriate object type and may be an object or a collection. You click on a node to show the properties of the object in the node's Tag in a property grid. A property may be a collection but currently I am not implementing UI collection editors in the propertygrid.

I am still examining TypeConverters, although the documentation is not real clear for me yet.

Example:

Code:
'Collection -Managed independently in the tree (i.e Add/Delete/Edit properties)
'Has a PathsNode that inherits TreeNode, as it's U.I.
'Is the tag data for a PathsNode

Public Class Paths 
Inherits CollectionBase 

'Retrieves an item from the collection by index 
    Default Public Property Item(ByVal Index As Integer) As Path 
        Get 
            Return CType(list.Item(Index), Path) 
        End Get 
        Set(ByVal Value As Path) 
            list.Item(Index) = Value 
        End Set 
    End Property 

'Add function 
'Remove function 
'.Etc...... 

end class 


'This is the class for items added to the Paths Collection
'Has it's own Node inherited from TreeNode
'Is type of Tag data for node
public class Path 

  private _Property1 as type 

  public property Property1 as type 
    'get 
    'set 
  end property 

'etc...

end class 


'This is a separate class
'Has a Node that derives from Treenode
'Is Tag data for it's node type
'Another Class 
public class AnotherItem 

  private _AnotherProperty as string 
  private _PathProperty as Path 

  public sub New 

  end sub 

  public property AnotherProperty() as string 

    'get 
    'set 

  End property 

'*****************************************************
'THIS IS THE PROPERTY THAT I WANT TO MANAGE IN PROPERTYGRID!
'HOW TO MAKE THIS SHOW IN THE PROPERTY GRID AS A DROP DOWN 
'TO SELECT FROM ITEMS IN THE PATHS COLLECTION ABOVE AND 
'REFLECT THE OBJECT VALUES.
'ALSO, CANNOT EDIT VALUES OF SELECTED OBJECT HERE

  <CategoryAttribute("Details"), _ 
  TypeConverter(GetType(ExpandableObjectConverterForItem)), _ 
  Browsable(True), _ 
  PropertyOrder(9), _ 
  [ReadOnly](False), _ 
  BindableAttribute(False), _ 
  DesignOnly(False), _ 
  DescriptionAttribute("Path of this Item")> _ 
  public property PathProperty as Path 

    'get 
    'set 

  end property 

end class
 
RobEmDee said:
scotty:
Sorry, but my experience with coding VS is very limited...wish I could help more.
I noticed you have a mix of C# and VB...are you working from an example you downloaded from somewhere? I'd like to check it out.


Thanks anyway RobEmDee. The sloppy bit of code I posted was really 'Pseudo' based on what I have already written in VB. I was just trying to get conceptual feedback on better understanding how to customize TypeConverters. I have decided to forget this approach and instead will use a context menu in my treeview.
 
Back
Top