Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Property Grid
  New Posts New Posts RSS Feed - How to determine an Item is a category?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to determine an Item is a category?

 Post Reply Post Reply
Author
Message
ianp View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 19 December 2003
Location: United Kingdom
Status: Offline
Points: 119
Post Options Post Options   Thanks (0) Thanks(0)   Quote ianp Quote  Post ReplyReply Direct Link To This Post Topic: How to determine an Item is a category?
    Posted: 22 June 2005 at 1:45am

In the RClick event of the PropertyGrid, I display a popup menu. The menu displayed varies depending on whether the item passed to the RClick event is a category or a child item.

However, I cannot seem to find any way of the PropertyGrid control telling me whether the Item is a category or not.

I can manually work it out using

  • Comparing the Item.Id to those in the categories collection, but the collection only includes Items created using the "AddCategory" method and the ID is not necessarily unique
  • "Type = PropertyItemCategory", but this only works for "Child Categories", i.e. those created using "AddChildItem(PropertyItemCategory..."

So here's my questions:

  1. Why doesn't the categories collection include all categories?
  2. Why are items in the categories collection set to Type = PropertyItemString?
  3. Why does the control allow for duplication of ID values?

See Sample Code below:

Option Explicit

Private Sub Form_Load()
Dim xpgCategory1 As XtremePropertyGrid.PropertyGridItem
Dim xpgCategory2 As XtremePropertyGrid.PropertyGridItem
Dim xpgCategory3 As XtremePropertyGrid.PropertyGridItem
Dim xpgCategory4 As XtremePropertyGrid.PropertyGridItem
Dim xpgItem As XtremePropertyGrid.PropertyGridItem

  ' Add PropertyGridItem
  Set xpgCategory1 = wndPropertyGrid.AddCategory("Category 1")
  xpgCategory1.ID = 32
  Set xpgItem = xpgCategory1.AddChildItem(PropertyItemString, "Method", "AddCategory")
  Set xpgCategory2 = xpgCategory1.AddChildItem(PropertyItemString, "Category 2", "")
  Set xpgItem = xpgCategory2.AddChildItem(PropertyItemString, "Method", "Child Item with childItems")
  Set xpgCategory3 = xpgCategory1.AddChildItem(PropertyItemCategory, "Category 3", "")
  Set xpgItem = xpgCategory3.AddChildItem(PropertyItemString, "Method", "Child Item as category")
  xpgItem .ID = 32
  Set xpgCategory4 = wndPropertyGrid.AddCategory("Category 4")
 
  ' Expand Categories created via AddCategory method
  For Each xpgItem In wndPropertyGrid.Categories
    xpgItem.Expanded = True
  Next
End Sub

Private Sub wndPropertyGrid_RClick(ByVal Item As XtremePropertyGrid.IPropertyGridItem)
Dim bCategory As Boolean
Dim xpgCategory As XtremePropertyGrid.PropertyGridItem

  ' Is Item a Category?
  For Each xpgCategory In wndPropertyGrid.Categories
    If Item.Id = xpgCategory.Id Then bCategory = True: Exit For
  Next
  bCategory = bCategory Or (Item.Type = PropertyItemCategory)

  If bCategory Then
    Debug.Print "Category: " & "Caption: " & Item.Caption; " Type: " & Item.Type; " Childs: " & Item.Childs.Count
  Else
    Debug.Print "Item: " & "Caption: " & Item.Caption; " Type: " & Item.Type; " Childs: " & Item.Childs.Count
  End If
End Sub

 



Edited by ianp
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 22 June 2005 at 3:30am

Thank you for this post.

1. Right, for next version root category will have PropertyItemCategory type.

2. For now, you can check Parent property of the Item to determine if it root category. It must be "Nothing".

Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
ianp View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 19 December 2003
Location: United Kingdom
Status: Offline
Points: 119
Post Options Post Options   Thanks (0) Thanks(0)   Quote ianp Quote  Post ReplyReply Direct Link To This Post Posted: 22 June 2005 at 3:50am

thanks oleg... waiting on the next release with great anticipation!

Any thoughts on the Item.ID values not forced to be unique? Should the control prevent duplicate ID's being set?

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.219 seconds.