Print Page | Close Window

How to determine an Item is a category?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Property Grid
Forum Description: Topics Related to Codejock Property Grid
URL: http://forum.codejock.com/forum_posts.asp?TID=2429
Printed Date: 15 May 2024 at 8:05am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to determine an Item is a category?
Posted By: ianp
Subject: How to determine an Item is a category?
Date 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

 




Replies:
Posted By: Oleg
Date 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


Posted By: ianp
Date 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?




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net