Good Afternoon,
I've recently downloaded the latest trial release of WinForms UI controls and our code to set a custom contextmenustrip on a Grid view no longer works.
We need to do this programatically, based on the row being clicked as below:
Private
Sub
radGrdHistory_ContextMenuOpening(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.ContextMenuOpeningEventArgs)
Handles
radGrdHistory.ContextMenuOpening
If
TypeOf
e.ContextMenuProvider
Is
Telerik.WinControls.UI.GridHeaderCellElement
Or
TypeOf
e.ContextMenuProvider
Is
Telerik.WinControls.UI.GridFilterCellElement
Then
radGrdHistory.ContextMenuStrip =
Nothing
Else
BuildAppointmentTypeRightClickMenu()
radGrdHistory.ContextMenuStrip = cmsAppointment
End
If
End
Sub
Using the Q1 2014 version this correctly showed our cmsAppointment contextmenustrip when rightclicking a grid element but this no longer occurs. I just see a context menu with 'Copy' and nothing else.
All the reading on the docs just says to use the ContextMenu properly and doesn't say anything about ContextMenuStrip. Has support been discontinued for this? Do I need to change all my contextmenustrips to contextmenus? Or do I need to write the code to show the CMS manually (say, off a right click event?).
17 Answers, 1 is accepted
Thank you for writing.
It appears that this is an issue and the ContextMenuStrip and ContextMenu properties are not working with the latest version. I have logged it in our Feedback Portal. You can track the item for status changes and add your vote for it here.
To workaround this you can use RadContextMenu instead. More information is available here: Custom Context Menus.
Your Telerik Points have been updated for this report.
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Telerik
Thanks for the quick reply.
We are considering renewing our license to get the latest version but we don't have the resources on hand to re-code all our Context Menus application wide.
Do you know the latest version where these properties are still working? Is it possible to download trials for this, slightly older, version? If we renew, do we also have access to all the versions PRIOR to the one available at renewal date?
Thank you for writing back.
This is working with the previous official release - UI for WinForms Q3 2015 (version 2015.3.930). If you have a licence you will be able to download older versions. Detailed information about this is available here: Download Product Files.
Generally we do not provide a way for downloading older trial versions. However, you can ask our sales department, perhaps they will be able to provide you with such version.
I hope this helps.
Regards,
Dimitar
Telerik
We have a similar problem. For most of our RadGridViews, we are setting the ContextMenuStrip to a Windows.Forms.ContextMenuStrip. You have suggested above to use RadContextMenu instead, but it would be a big job to change all of our Windows.Forms.ContextMenuStrips to RadContextMenus. Is there a workaround we can use to get our Windows.Forms.ContextMenuStrips working?
Thank you for writing.
You can disable the default context menus by setting the following properties:
radGridView1.AllowCellContextMenu =
false
;
radGridView1.AllowColumnHeaderContextMenu =
false
;
This way the ContextMenuStrip should be shown properly.
In addition, I want to say that this is already resolved and the fix will be available in the next official release.
I hope this will be useful.
Dimitar
Telerik
Hi Dimitar,
I've downloaded the Q1 2016 release made available yesterday but still can't get the standard Windows context menus to show on the Rad Grid view.
I also tried the workaround described above on the new release but this just has the affect of having NO context menu show (which is kind of what I'd expect anyway).
I'll probably roll back again to the working version from 2014 and look out for further releases down the track. Hopefully it can be fixed soon.
Regards,
Dave
Thank you for writing back.
I just tested this and it is working fine on my side. I have attached my test project. Could you please check it and let me know how it differs from your real setup?
Thank you in advance for your patience and cooperation.
Regards,
Dimitar
Telerik
Hey,
I wrote a huge reply and it was lost when posting!
In summary it seems the ContextMenuOpening event is not firing when AllowCellContextMenu = False
I've modified your project to demonstrate this. We need this event to fire since we need to set the CMS contextually based upon the data grid row being right clicked.
We need either of the two following behaviors:
1. The correct (non default) CMS needs to show with AllowCellContextMenu = True (this is how it works with our current 2014 telerik version) - This is also the most logical way for it to work
2. The ContextMenuOpening event needs to fire with AllowCellContextMenu = False
This is not as thorough as the post I lost so please ask any questions if you are not seeing the problem
It seems I can't attach a zip file so the code change to your project is below:
Imports
System
Imports
System.Collections.Generic
Imports
System.ComponentModel
Imports
System.Data
Imports
System.Drawing
Imports
System.Linq
Imports
System.Text
Imports
System.Windows.Forms
Imports
Telerik.WinControls.UI
Namespace
_991034
Partial
Public
Class
RadForm1
Inherits
Telerik.WinControls.UI.RadForm
Public
Sub
New
()
InitializeComponent()
radGridView1.DataSource = GetTable()
radGridView1.EnableFiltering =
True
strip.Items.Add(
"Item1"
)
radGridView1.ContextMenuStrip = strip
' I can't have these since if this is set the event below does not fire
'radGridView1.AllowCellContextMenu = False
'radGridView1.AllowColumnHeaderContextMenu = False
End
Sub
Private
strip
As
New
ContextMenuStrip()
Private
Sub
RadForm1_Load(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
Me
.Load
End
Sub
Private
Shared
Function
GetTable()
As
DataTable
Dim
table
As
New
DataTable()
table.Columns.Add(
"Dosage"
,
GetType
(
Integer
))
table.Columns.Add(
"Drug"
,
GetType
(
String
))
table.Columns.Add(
"Name"
,
GetType
(
String
))
table.Columns.Add(
"Date"
,
GetType
(
Date
))
table.Rows.Add(25,
"Indocin"
,
"David"
,
Date
.Now)
table.Rows.Add(50,
"Enebrel"
,
"Sam"
,
Date
.Now)
table.Rows.Add(10,
"Hydralazine"
,
"Christoff"
,
Date
.Now)
table.Rows.Add(21,
"Combivent"
,
"Janet"
,
Date
.Now)
table.Rows.Add(100,
"Dilantin"
,
"Melanie"
,
Date
.Now)
Return
table
End
Function
Dim
counter
As
Integer
= 1
Private
Sub
radGrdHistory_ContextMenuOpening(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.ContextMenuOpeningEventArgs)
Handles
radGridView1.ContextMenuOpening
' This event is firing when AllowCellContextMenu = True
If
TypeOf
e.ContextMenuProvider
Is
Telerik.WinControls.UI.GridHeaderCellElement
Or
TypeOf
e.ContextMenuProvider
Is
Telerik.WinControls.UI.GridFilterCellElement
Then
radGridView1.ContextMenuStrip =
Nothing
Else
Dim
stripEventHandler
As
New
ContextMenuStrip()
stripEventHandler.Items.Add(
"Event Handler: "
+ counter.ToString())
radGridView1.ContextMenuStrip = stripEventHandler
' I have to set this to False here if I want to see my custom CMS (Although this is still messy as it
' overlays them on top of each other)
radGridView1.AllowCellContextMenu =
False
' Now that this is set this handler never fires again and I'm 'stuck' with the CMS with the counter on '1'.
' I need to be able to generate a CMS on every right click!
counter = counter + 1
End
If
End
Sub
End
Class
End
Namespace
I also had to change a line of the designer line 68 to include 'WithEvents' to use the event handler:
Private
WithEvents
radGridView1
As
Telerik.WinControls.UI.RadGridView
Thank you for writing back.
Let me iterate your requirement, in order to make sure we are on the same page. Your goal is to show the built-in RadGridView context menu for filtering and header rows, while, for data rows, you would like to show your own ContextMenuStrip? Is that correct and is there is anything else besides this?
If this is the case, and the code you showed below is what you used with version Q1 2014, I think that you had two context menus showing when you click on a data row (and new row as well for that matter). Perhaps, if your ContextMenuStrip was big enough, it was covering the grid's context menu and you were not able to see it.
With the recent changes we introduced, what we did is to show the ContextMenu/ContextMenuStrip assigned to the control, only the grid context menus are disabled - AllowColumnHeaderContextMenu and AllowCellContextMenu.
Having this in mind, in order to achieve scenario, you have to options:
1. Disable the grid default context menu for data rows by setting the AllowCellContextMenu to false and use the MouseDown event to show the strip. From the clicked cell, you can get the row and build your menu accordingly:
Private
Sub
radGridView1_MouseDown(
ByVal
sender
As
Object
,
ByVal
e
As
MouseEventArgs)
Dim
clickedElement = radGridView1.ElementTree.GetElementAtPoint(e.Location)
If
Not
(
TypeOf
clickedElement
Is
GridDataCellElement)
AndAlso
Not
(
TypeOf
clickedElement
Is
GridFilterCellElement)
Then
PopulateItems()
strip.Show(
Me
.radGridView1, e.Location)
End
If
End
Sub
2. Replace the ContextMenuStrip with RadContextMenu and modify the built-in context menus: Modifying the Default Context Menu. With this approach, you will also have your menus themed with the application theme.
I hope this helps. Let me know if any questions arise or if I missed something in your scenario.
Regards, Dimitar
Telerik
Hi Dimitar,
I think we're on the same page now. From the sounds of your last reply it does not sound like you intend to restore the control to the way it used to work, or to allow complex CMS generation without resorting to messy mouseclick handing
This being the case we will continue to use the 2014 version for the foreseeable future and if we have to change I would hesitantly think we'd replace the menus with the default one as per your suggestion (2). The link shows how to add items to this, but is it also possible to clear all the existing items?
Hello,
Additional question: Is this documentation still up to date? Is this still a accepted methodology with Context menus, this doesn't seem to work in the 2014 version
http://docs.telerik.com/devtools/winforms/gridview/context-menus/custom-context-menus
Thank you for writing back.
You can remove the default items with the Clear method:
Private
Sub
radGridView1_ContextMenuOpening1(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.WinControls.UI.ContextMenuOpeningEventArgs)
e.ContextMenu.Items.Clear()
Dim
customMenuItem
As
New
RadMenuItem()
customMenuItem.Text =
"Custom Data Operation"
e.ContextMenu.Items.Add(customMenuItem)
End
Sub
In addition, the documentation is up to date and the example should work without issues. I have tested this with the 2014 version as well, and it is working as expected (see attached video).
Let me know if you have additional questions.
Regards,
Dimitar
Telerik
Thanks Dimitar,
I was doing something wrong with the example in the second - thanks for clarifying it!
Please update us and let us know if you decide to fix the implementation of the Windows context menu strip such that you will allow dynamic generation of the strip content without having to use the RadContextMenu.
For now, we will stick with 2014 as I believe it's a better version in how it handles context menus. We may choose to migrate all our menus to RadContextMenus over time.
Thanks for all the support
Thank you for writing back.
I understand that it requires extra efforts to fix something that was previously working. However, we believe that the current behavior is better than the previous one and we do not have plans for changing it. Please note that you can use the ContextMenu/ContextMenuStrip with the MouseDown event, which will require very little coding - just moving the logic from one event handler to another. In fact, switching the context menus to RadContextMenus should not take much time as well. How many projects and context menus you have in total?
Regards,
Dimitar
Telerik
Hi Dimitar,
This might be obvious and I am missing something simple, but how do you access the row using the work around with the MouseDown event?
I need to filter the context menu depending on the value of another cell in the row that is clicked on.
Thank you for writing back.
Here is a sample code snippet demonstrating how to access the row by the clicked GridDataCellElement:
Private
Sub
RadGridView1_MouseDown(sender
As
Object
, e
As
MouseEventArgs)
Handles
RadGridView1.MouseDown
Dim
clickedElement
As
GridDataCellElement = TryCast(RadGridView1.ElementTree.GetElementAtPoint(e.Location), GridDataCellElement)
If
Not
(clickedElement IsNot
Nothing
AndAlso
Not
(
TypeOf
clickedElement
Is
GridFilterCellElement))
Then
Dim
row
As
GridViewRowInfo = clickedElement.RowInfo
'access the row
End
If
End
Sub
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik