none
Use DataGridView ContextMenus from MS Access in VB.NET Application

    Question

  • Is there a way to use the DataGridView ContextMenus from Microsoft Access in my VB.NET Application datagridview controls?  I have several users that are familiar with the datagridview context menus in Access shown below and I'd like to use them in my VB.NET application without having to build them myself.

    CheckBox Context Menu:


    Ryan
    Wednesday, November 23, 2011 5:05 PM

Answers

  • Hi Ryan,

    Hang in there, the terminology used in the documentation can sometimes cause brain damage. ;)

    If you drill down through the documentation, you will find that in reality all the items in a ZZZZStrip (where ZZZZ = ContextMenu, Menu, Tool, or Status) are really ToolStripItems.  This is really a good thing as you can host a control that is derived from then System.Windows.Forms.Control in a ToolStripItem.

    Now with that boring background information stated, let's get you an example to demonstrate the fun stuff.

    I suggest that you start by using the MonthCalandar control as Microsoft has a good example of that one here:
    How to: Wrap a Windows Forms Control with ToolStripControlHost

    The only thing they do not show you how to do, is to get it to show up in the designer.  To do that, add this to the top of the class declaration.

    <System.ComponentModel.DesignTimeVisibleAttribute(True)> _
    <System.ComponentModel.DesignerCategory("code"), _
    System.Windows.Forms.Design.ToolStripItemDesignerAvailability( _
    System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ToolStrip Or _
    System.Windows.Forms.Design.ToolStripItemDesignerAvailability.StatusStrip Or _
    System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ContextMenuStrip Or _
    System.Windows.Forms.Design.ToolStripItemDesignerAvailability.MenuStrip)> _
    Public Class ToolStripMonthCalendar

    Once you get the hang on using this one, you can create one to host the treeview that showed in your picture above.

    Have fun, and don't be afraid to ask questions.

     

    Tuesday, December 06, 2011 1:47 AM

All replies

  • AFAIK has Access no datagridview so it is also not possible to use the same kind of combobox in a .Net DataGridView. 

    It is asking in an analogy to add the steer of a scooter to a plane.

    If you ask yourself why I write this, it is that you should not suspect what you mean with an Access DatagridView combobox.

    Try to explain what you want to do, but don't let us investigate what kind of features MS Access has.

     


    Success
    Cor
    Wednesday, November 23, 2011 5:43 PM
  • Ok, so I can't use the same context menu from Access in my application.  So I will have to build my own.  I need to create a few context menus because they will differ in appearance based on what object the user right-clicks on.  For example, one context menu will have to be built for each of the following scenarios:

    1.)  When a user clicks a cell with text datatype in a datagridview.

    2.)  When a user clicks a cell with boolean data type in a datagridview.

    3.)  When a user clicks a column header in a datagridview.

    etc.

    I will need to use these context menus in several forms.  Is there a way to build a context menu then share it with several forms?  Do I have to add a Component to my project then add all my different context menus to it?  Should I build the menus and save them in a dll file.  What is the ideal way to do this?

    Thanks,

    Ryan


    Ryan
    Wednesday, November 23, 2011 7:16 PM
  • Hi Ryan,

    Nice to see you again.

    >> Is there a way to build a context menu then share it with several forms?

    Yes, you can add a new class inherits contextmenustrip class, with "public" modifier, then you can use it in your other forms. And in the last part of the webpage, there is a code sample of how to use contextmenustrip. Please take a look at it.

    >> Do I have to add a Component to my project then add all my different context menus to it?

    No, you needn't to do this, please make a seprate class for each kind of contextmenustrip.

    >>Should I build the menus and save them in a dll file.

    If you have more than one project, I suggest you go to this way. But if there is only one project, you can just make them  in the same project.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, November 24, 2011 1:37 PM
    Moderator
  • Hi Ryan,

    We have not heard from you in a few days.

    Please post bast at your convenience if we can assist further.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, December 01, 2011 7:56 AM
    Moderator
  • Thanks for checking in Mike,

    I haven't quiet figured this all out yet.  I thought I could use the component to create my ContextMenuStrips at design time instead of your suggestion to create a class and then creating the ContextMenuStrip at runtime.  Is this not the ideal way to use a Component?

    Since we are talking about ContextMenus I have come across two other problems:

    1.)  I want to design a ContextMenuStrip for data type.  For example, I will build one for Text, one for Boolean and one for Numerics.  When the user right-clicks a column in my DataGridView how do I test the data type of that column?  For example, if the data type is boolean I will open the Boolean ContextMenuStrip.

    2.)  Is it possible to add a CheckedListBox to my ContextMenuStrip?  If the user right-clicks the column header I want to find all the unique values in the underlying datatable of my DataGridView column and put them in the CheckedListBox then add that CheckedListBox to my ContextMenuStrip.  I will then allow the users to check or uncheck items.  When they are finished I will filter the column using their selections.  Kind of like when you filter columns in MS Excel or Access.

    Does this make sense?

    Thanks, 


    Ryan
    Friday, December 02, 2011 1:45 PM
  • Hi Ryan,

    There is a component named DataGridView Filter Popup at Code Project that does what you seem to be looking for that works on a DataGridView used to filter column data which recognizes data types. The basic operation is one line of code. Also the component can be easily customized.


    KSG
    • Proposed as answer by Mike FengModerator Monday, December 05, 2011 11:55 AM
    • Unproposed as answer by Ryan0827 Monday, December 05, 2011 10:49 PM
    Friday, December 02, 2011 2:25 PM
    Moderator
  • Hi Ryan,

    I agree with Kevin's suggestion. Is it helpful?

    If you have any concerns, please feel free to let me know.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, December 05, 2011 12:01 PM
    Moderator
  • Mike,

    Kevin's suggestion is pretty close to what I'm looking for, but I would prefer to customize my own to fit all the details of my application.  I'm still looking for a solution to two questions which would help me get over this hump.

    1.) I thought I could use the component to create my ContextMenuStrips at design time instead of your suggestion to create a class and then creating the ContextMenuStrip at runtime.  Is this not the ideal way to use a Component?  I'm doing my best to learn and was wondering why you suggest to use to use a class instead of the componet?

    2.)  How can I add a CheckedListBox control to my ContextMenuStrip?  Below is an image of the ContextMenuStrip used in Excel when filtering data in a column.  I would love to be able to get all the unique values of the column the user right-clicks and put those values in a CheckedListBox.  Is this possible?  I couldn't find any articles online about this.

    Forgive, because I am new to VB.NET and I'm doing my best to absorb as much as possible.

    Thanks for sticking with me on this,


    Ryan
    Monday, December 05, 2011 10:51 PM
  • Hi Ryan,

    Hang in there, the terminology used in the documentation can sometimes cause brain damage. ;)

    If you drill down through the documentation, you will find that in reality all the items in a ZZZZStrip (where ZZZZ = ContextMenu, Menu, Tool, or Status) are really ToolStripItems.  This is really a good thing as you can host a control that is derived from then System.Windows.Forms.Control in a ToolStripItem.

    Now with that boring background information stated, let's get you an example to demonstrate the fun stuff.

    I suggest that you start by using the MonthCalandar control as Microsoft has a good example of that one here:
    How to: Wrap a Windows Forms Control with ToolStripControlHost

    The only thing they do not show you how to do, is to get it to show up in the designer.  To do that, add this to the top of the class declaration.

    <System.ComponentModel.DesignTimeVisibleAttribute(True)> _
    <System.ComponentModel.DesignerCategory("code"), _
    System.Windows.Forms.Design.ToolStripItemDesignerAvailability( _
    System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ToolStrip Or _
    System.Windows.Forms.Design.ToolStripItemDesignerAvailability.StatusStrip Or _
    System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ContextMenuStrip Or _
    System.Windows.Forms.Design.ToolStripItemDesignerAvailability.MenuStrip)> _
    Public Class ToolStripMonthCalendar

    Once you get the hang on using this one, you can create one to host the treeview that showed in your picture above.

    Have fun, and don't be afraid to ask questions.

     

    Tuesday, December 06, 2011 1:47 AM
  • Hi Ryan,

    Any update?

    Is TnTinMN's suggestion helpful?

    If you need further assistance, please feel free to let me know.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, December 08, 2011 10:15 AM
    Moderator