
Hilda Kenny
Top achievements
Rank 1
Hilda Kenny
asked on 01 Oct 2010, 01:11 PM
hi,
I have a radcontextmenu which only seems to work once. When I right click, my new items are added to the default menu, but when I go to do it again, I get the error message: 'Cannot remove the specified item because it was not found in the specified collection.'
here is the code:
Private
Sub grdSearch_ContextMenuOpening(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.ContextMenuOpeningEventArgs) Handles grdSearch.ContextMenuOpening
Try
e.ContextMenu.Items.AddRange(rcmDebts.Items)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
10 Answers, 1 is accepted
0
Hello Hilda Kenny,
The context menu is generated every time when it is being shown. So, you have to add your items every time when handling the ContextMenuOpening event. Find more information about RadGridView context menus in this help article.
I hope this helps.
Regards,
Jack
the Telerik team
The context menu is generated every time when it is being shown. So, you have to add your items every time when handling the ContextMenuOpening event. Find more information about RadGridView context menus in this help article.
I hope this helps.
Regards,
Jack
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0

Hilda Kenny
Top achievements
Rank 1
answered on 04 Oct 2010, 09:30 AM
That's what I am currently doing, if you see the code above
0

Richard Slade
Top achievements
Rank 2
answered on 04 Oct 2010, 09:57 AM
Hi Hilda,
Where are the rcmDebts.Items coming from? See example below where the item is created each time the context menu item opens.
Where are the rcmDebts.Items coming from? See example below where the item is created each time the context menu item opens.
Private
Sub
GridView_ContextMenuOpening(
ByVal
sender
As
System.
Object
, _
ByVal
e
As
ContextMenuOpeningEventArgs)
Handles
GridView.ContextMenuOpening
If
TypeOf
e.ContextMenuProvider
Is
Telerik.WinControls.UI.GridDataCellElement _
AndAlso
GridView.SelectedRows.Count > 0
Then
' Clear any current items if you don't want the default menu
e.ContextMenu.Items.Clear()
'Declare a context menu item
Dim
contextMenuItemMyItem
As
New
RadMenuItem()
' Add the item
With
contextMenuItemMyItem
.Text =
"My Item"
.Image =
' An Image
.ToolTipText =
"A Tooltip"
.Enabled =
True
End
With
'Insert it at a position
e.ContextMenu.Items.Insert(0, contextMenuItemMyItem)
'Add a handler
AddHandler
contextMenuItemMyItemt.Click,
AddressOf
ContextMenuItemMyItem_Click
End
If
End
Sub
Private
Sub
ContextMenuItemMyItem_Click(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
' Do Something
End
Sub
0

Hilda Kenny
Top achievements
Rank 1
answered on 04 Oct 2010, 11:17 AM
I dropped the rcm from the toolbox and added it to the form. So in the designer I added my items.
Thanks for any help.
Thanks for any help.
0

Richard Slade
Top achievements
Rank 2
answered on 04 Oct 2010, 11:47 AM
What you're doing is correct. You can add a RadContextMenu and perform an AddRange on the ContextMenu to add the items from the RadContextMenu that you have dragged onto the designer. ( though you may want to wrap this in) ...
What does the stack trace read for the "Cannot remove the specified item because it was not found in the specified collection
" message?
My first guess is that it is not related to the menu item being rendered but that on click of the item the first time round, you are removing something from a collection that you are affecting which is now no longer there.
If
TypeOf
e.ContextMenuProvider
Is
Telerik.WinControls.UI.GridDataCellElement _
AndAlso
GridView.SelectedRows.Count > 0
Then
' Add Range here
end if
What does the stack trace read for the "Cannot remove the specified item because it was not found in the specified collection
" message?
My first guess is that it is not related to the menu item being rendered but that on click of the item the first time round, you are removing something from a collection that you are affecting which is now no longer there.
0

Hilda Kenny
Top achievements
Rank 1
answered on 04 Oct 2010, 12:51 PM
Hi, I'll get the stack trace once I get my app running again with SP2, Thanks for the reply.
0

Richard Slade
Top achievements
Rank 2
answered on 05 Oct 2010, 10:43 PM
Hi Hilda,
Did this work for you?
Richard
Did this work for you?
Richard
0
Hello gyus,
I have tried the scenario that Hilda has and the menu items have been added correctly. I am using the latest official Q2 2010 SP2 release. Hilda, please try the latest version of RadControls and let me know if you still has any issues on that.
Richard, I have updated your Telerik points for your help on this topic.
Sincerely yours,
Martin Vasilev
the Telerik team
I have tried the scenario that Hilda has and the menu items have been added correctly. I am using the latest official Q2 2010 SP2 release. Hilda, please try the latest version of RadControls and let me know if you still has any issues on that.
Richard, I have updated your Telerik points for your help on this topic.
Sincerely yours,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

Hilda Kenny
Top achievements
Rank 1
answered on 08 Oct 2010, 03:02 PM
Hi,
Sorry about the delay in getting back to you. I have it working now. I uninstalled the controls and reinstalled. I added all the references manually instead of using the project update utility and added the controls manually to the toolbox. It works now, so maybe the update utility had something to do with the error. Thanks for your posts.
Sorry about the delay in getting back to you. I have it working now. I uninstalled the controls and reinstalled. I added all the references manually instead of using the project update utility and added the controls manually to the toolbox. It works now, so maybe the update utility had something to do with the error. Thanks for your posts.
0
Hi Hilda Kenny,
I am glad that you have managed to resolve the issues.
If you need further assistance, feel free to contact me.
Kind regards,
Martin Vasilev
the Telerik team
I am glad that you have managed to resolve the issues.
If you need further assistance, feel free to contact me.
Kind regards,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items