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:
- Why doesn't the categories collection include all categories?
- Why are items in the categories collection set to Type = PropertyItemString?
- 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 |
|