Currently I am creating a constrained item from a adodb recordset which contains a primary key field and a descriptive text field. I would like the user to select a value for the property using the descriptive text field, but use the primary key in my code.
Using a standard VB.ComboBox, I would add an item using the descriptive field in the recordset and then set the ItemData using the Primary Key field.
However, with the PropertyGrid I need to work around the fact that an item constraint only has an Index and Caption property, it does not have an "ItemData" property.
Here's what I'm doing (I've taken the recordset out of the code for simplicity):
Option Explicit Dim m_OS() As Long
Private Sub Form_Load() Dim pgC As XtremePropertyGrid.PropertyGridItem Dim pgI As XtremePropertyGrid.PropertyGridItem With Me.PropertyGrid1 Set pgC = .AddCategory("test") pgC.Expanded = True Set pgI = pgC.AddChildItem(PropertyItemString, "prop", "1") Set pgI = Nothing Set pgI = pgC.AddChildItem(PropertyItemString, "Operating System", Null) pgI.ConstraintEdit = True pgI.Flags = ItemHasComboButton ' would usually be loaded from an adodb.recordset ReDim m_OS(3) As Long pgI.Constraints.Add "Windows XP": m_OS(1) = 3 pgI.Constraints.Add "Windows 2000": m_OS(2) = 1 pgI.Constraints.Add "Windows 98": m_OS(3) = 2 End With End Sub
Private Sub PropertyGrid1_ValueChanged(ByVal Item As XtremePropertyGrid.IPropertyGridItem) Dim i As Long If Item.Caption = "Operating System" Then For i = 1 To Item.Constraints.Count If Item.Constraints(i) = Item.Value Then MsgBox "Constraint Index is " & i & vbCrLf & "Contraint Key is " & m_OS(i): Exit For Next End If End Sub |
Is there any way of, at the very least, exposing the index for the constraint selected e.g.
Item.Constraints("Windows 2000").Index ' --> which would return 2 |
or, ideally, adding an ItemData (and/or Key) to the constraint? e.g.
' Add Constraints: Item.Constraints.Add "Windows XP", 3 Item.Constraints.Add "Windows 2000", 1 Item.Constraints.Add "Windows 98", 2 ' Read Constraints: Item.Constraints("Windows 2000").Index ' --> which would return 2 Item.Constraints("Windows 2000").ItemData ' --> which would return 1 Item.Constraints(2).Caption ' --> which would return "Windows 2000" Item.Constraints(2).ItemData ' --> which would return 1 |
Better yet, be able to access an items selected constraint directly from the item e.g.
Item.SelectedConstraint.Index ' --> which would return 2 Item.SelectedConstraint.ItemData ' --> which would return 1 |
|