Hi Lance,
Based on my understanding, you want to display the "reset", "description"
context menu for PropertyGrid at runtime.
Actually, at runtime, there will be no that design-time context menu for
your PropertyGrid. But you may add a context menu of this function
yourself.
For "reset" menu item, you may get information of the selected property
through the PropertyGrid.SelectedGridItem.PropertyDescriptor, then you may
determine the if it can reset, through PropertyDescriptor.CanResetValue()
method. At last, you may implement the reset function through
PropertyGrid.SelectedGridItem.PropertyDescriptor.ResetValue method.
For "description" menu item, you may control the function through
PropertyGrid.HelpVisible property.
I have writen a sample for you like this:
1). First, add a context menu in the designer, like this:
Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem1, Me.MenuItem2})
Me.MenuItem1.Index = 0
Me.MenuItem1.Text = "Reset"
Me.MenuItem2.Index = 1
Me.MenuItem2.Text = "Description"
2). Apply the "reset" and "description" logic for your context menu.
Private Sub ContextMenu1_Popup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ContextMenu1.Popup
Dim pd As System.ComponentModel.PropertyDescriptor =
Me.PropertyGrid1.SelectedGridItem.PropertyDescriptor
If pd.CanResetValue(Me.TextBox1) Then
Me.MenuItem1.Enabled = True
Else
Me.MenuItem1.Enabled = False
End If
If Me.PropertyGrid1.HelpVisible = True Then
Me.MenuItem2.Checked = True
Else
Me.MenuItem2.Checked = False
End If
End Sub
Private Sub MenuItem1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click
Me.PropertyGrid1.SelectedGridItem.PropertyDescriptor.ResetValue(Me.TextBox1)
End Sub
Private Sub MenuItem2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
Me.PropertyGrid1.HelpVisible = Not Me.PropertyGrid1.HelpVisible
End Sub
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.