none
PropertyGrid - How to Open A Window In A Dropdown Menu? RRS feed

  • Question

  • Hey there guys. 

    I've been trying to open a new window when a dropdown item is clicked (Enum or string) but no luck so far.

    In the screenshot below when Edit Zones... item is clicked, a new window appears.

    How can I make my code work like that?

    Thanks.



    • Edited by samialtas Sunday, April 7, 2019 6:38 PM
    Sunday, April 7, 2019 6:31 PM

Answers

  • Hello,

    This is done via UITypeEditors.

    See the following article/code sample should get you going but will need you to work with what they have done. Also the following code sample is a good resource.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by samialtas Sunday, April 21, 2019 8:37 PM
    Sunday, April 7, 2019 7:18 PM
    Moderator
  • Thanks for quick reply.

    So do I need to add a custom UITypeEditor? Is there any other workaround or something? I just want to keep my control as stock as possible.

    No, the UITypeEditor is actually used in the stock for a PropertyGrid which is what you are showing. If this is not a PropertyGrid then please indicate what type of control you are asking about.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Proposed as answer by Alex Li-MSFT Wednesday, April 17, 2019 8:27 AM
    • Marked as answer by samialtas Sunday, April 21, 2019 8:37 PM
    Monday, April 8, 2019 12:09 AM
    Moderator

All replies

  • Hello,

    This is done via UITypeEditors.

    See the following article/code sample should get you going but will need you to work with what they have done. Also the following code sample is a good resource.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by samialtas Sunday, April 21, 2019 8:37 PM
    Sunday, April 7, 2019 7:18 PM
    Moderator
  • Thanks for quick reply.

    So do I need to add a custom UITypeEditor? Is there any other workaround or something? I just want to keep my control as stock as possible.

    Sunday, April 7, 2019 7:22 PM
  • Hi

    Maybe this will help. This is a stand alone example. If you want to try it out, start a new Project, on the Form (Designer), add a Label1 and a ContextMenuStrip. Then Copy/Replace the default Form1 code with this code. Run to try it out.

    Basically, it assigns the ContextMenuStrip as the Form1 right click context menu and uses the same click event handler for all the menu items (sorts out which item in the code).

    Of course, I don't know exactly what items you need, but this might provide a start. Some comments included aid understanding.

    ' Form1 with ContextMenu1

    ' containing items: One, Two,

    ' Three (with subitems Thirty and

    ' ThirtyOne) and Four Option Strict On Option Explicit On Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' assign this ContextMenu to ' the main Form itself ContextMenuStrip = ContextMenuStrip1 End Sub Private Sub OneToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OneToolStripMenuItem.Click, TwoToolStripMenuItem.Click, FourToolStripMenuItem.Click, ThirtyToolStripMenuItem.Click, ThirtyOneToolStripMenuItem.Click ' cast sender to ToolStripMenuItem Dim ms As ToolStripMenuItem = DirectCast(sender, ToolStripMenuItem) ' display name of dropdown item Label1.Text = ms.Name & " CLICKED" ' select New Form to open based ' on dropdown name Select Case ms.Name Case "OneToolStripMenuItem" ' Open required Form ' for drop down item ' 'One' - for example Dim nf As New Form1 nf.Show() Case "TwoToolStripMenuItem" ' Open required Form ' for drop down item ' 'Two' Case "FourToolStripMenuItem" ' Open required Form ' for drop down item ' 'Four' Case "ThirtyToolStripMenuItem" ' Open required Form ' for drop down item ' 'Thirty' Case "ThirtyOneToolStripMenuItem" ' Open required Form ' for drop down item ' 'ThirtyOne' Case Else Label1.Text = Nothing End Select End Sub End Class



    Regards Les, Livingston, Scotland



    • Edited by leshay Monday, April 8, 2019 12:40 AM
    Sunday, April 7, 2019 11:12 PM
  • Thanks for quick reply.

    So do I need to add a custom UITypeEditor? Is there any other workaround or something? I just want to keep my control as stock as possible.

    No, the UITypeEditor is actually used in the stock for a PropertyGrid which is what you are showing. If this is not a PropertyGrid then please indicate what type of control you are asking about.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Proposed as answer by Alex Li-MSFT Wednesday, April 17, 2019 8:27 AM
    • Marked as answer by samialtas Sunday, April 21, 2019 8:37 PM
    Monday, April 8, 2019 12:09 AM
    Moderator