private void RadContextMenuOpportunities_Opened(object sender, RoutedEventArgs e)
{
RadTreeViewItem item = radContextMenuOpportunities.GetClickedElement<RadTreeViewItem>();
if(item!=null)
{
CreatePageOppMainItemTab(item);
}
}
I have ContextMenu within the tree. When I right click and open a menu item I'm not getting proper item. But I'm getting another RadTreeViewItem in same tree.
Is this the way to get clicked TreeViewItem?
RadTreeViewItem item = radContextMenuOpportunities.GetClickedElement<RadTreeViewItem>();
Thanks!
Priyastha
17 Answers, 1 is accepted
This is the way to get the clicked item so could you please send us your sample project so I will be able to investigate your problem.
On a side note, I'd like to inform you that we've just released an online tool that allows you to reduce the size of your Silverlight applications. For more information, please visit http://blogs.telerik.com/blogs/posts/10-06-10/telerik_assembly_minifier.aspx
Greetings,
Viktor Tsvetkov
the Telerik team
I have the same problem with RadGridView. In maybe 5-10% of the cases when I right-click on a row, a wrong row is returned by RadContextMenu.GetClickedElement<GridViewRow>(). To make it happen I just keep clicking on different rows, and eventually a random row is returned by GetClickedElement().
This is the code I have:
private
void
GridViewContextMenu_Opened(
object
sender, RoutedEventArgs e)
{
var row = ((RadContextMenu)sender).GetClickedElement<GridViewRow>();
RadContextMenu contextMenu = sender
as
RadContextMenu;
if
(row ==
null
)
{
contextMenu.IsOpen =
false
;
}
else
{
row.IsSelected =
true
;
}
}
<
telerik:RadGridView
>
<
telerik:RadContextMenu.ContextMenu
>
<
telerik:RadContextMenu
Opened
=
"GridViewContextMenu_Opened"
>
<
telerik:RadMenuItem
Header
=
"Edit"
Click
=
"EditMenuItem_Click"
/>
</
telerik:RadContextMenu
>
</
telerik:RadContextMenu.ContextMenu
>
...
</
telerik:RadGridView
>
Best regards,
Wiktor
I was not able to reproduce your issue. Could you please examine the attached sample project and modify it if I am missing something and could you please make a screencast of the undesired behavior?
Best wishes,
Viktor Tsvetkov
the Telerik team
Hi Viktor,
I can reproduce the result without making any changes to your project. However, the behavior is visible only when clicking on cells with text, and when I change IE zoom to 125%.
http://www.screencast.com/t/dwF14FCk
Best regards,
Wiktor
I can confrim that this is a bug, so I have logged it in our PITS under the name "ContextMenu: GetClickedElement does not return the correct element" and it will be ready for tracking and voting tomorrow the latest. I have updated your Telerik account.
Kind regards,
Viktor Tsvetkov
the Telerik team
It also appears after right-clicking the item to open the context menu, left clicking on another item doesn't appear change the selected item and if we were to apply an IsExpanded property on the element we thought we left-clicked, it would expand the previously selected right-clicked item.
Thoughts?
paul
Could you please send us a sample project that reproduces the problem?
Sincerely yours,
Viktor Tsvetkov
the Telerik team
I was wondering if this problem has been resolved. We are using version 2010.3.1314.1040. I ask because we are experiencing this problem. Thank you
We recently made a few changes in this functionality, that might be related to this problem. I would recommend trying the upcoming service pack early next week and checking if the problem persists. I am not 100% sure, but the update might have been included in the internal build from this week (version 2011.1.411), so it is also worth checking.
All the best,
Valeri Hristov
the Telerik team
I have updated to version 2011.1.627.1040 and I still have an issue with a context menu on a RadGridView.
When the application is running with browser zoom (IE9 115%) GetClickedElement returns the incorrect row.
I cannot find an issue in PITS for this.
Regards
Peran
GetClickedElement internally use VisualTreeHelper.FindElementsInHostCoordinates method.
Unfortunately FindElementsInHostCoordinates have a bug when browser is zoomed and does not return the real element (but the element which is over if the browser is at 100%).
We have reported it to Microsoft but there is still no fix.
Sorry for the caused inconvenience.
Kind regards,
Hristo
the Telerik team
Is there a link to the issue at Microsoft? If there is I would like to vote for it to be fixed.
As a work around, do you know how I could:
1) Check the browser zoom level at application start up.
2) Monitor for browser zoom changes whilst the application is running.
3) Get my application to automatically change the browser zoom back to 100%.
Thanks
Peran
Host.Settings.EnableAutoZoom = false;
Using IE 8, no zoom, default settings.
If you right-click to invoke the context menu anyware above the middle of the header of the treenode, I seem to get the correct node returned on my call to GetClickedElement(). If I right-click on the bottom half of the tree node headter, the call returns the next node in the tree (the one below the desired node).
I have not tested this for other behaviors, but it appears to point to there simply being a bug in the code that calculates the element at the right-click mouse position...perhaps using the center of the element as the determination of the target? I cannot say if this is isolated to VisualTreeHelper.FindElementsInHostCoordinates (by your comment, I assume this is a Microsoft routine) or just in the telerik code. Are they sure they are sending in the appropriate Point?
Just a thought...
Just my two cents.
We were unable to reproduce this issue. I've tested your scenario using Q2 2011 SP1.
Could you please send us sample project so that we can reproduce it?
Greetings,
Hristo
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
1. select a cell
2. Do right Click in any other cell, return the selected cell:
(Attach image)
return m_gridContextMenu.GetClickedElement<GridViewRow>();
I did not manage to reproduce the displayed in the screenshot issue with the latest Q3 2013 SP2 release of UI for Silverlight.
I would suggest that you take a look at the following help topic:
http://www.telerik.com/help/silverlight/radcontextmenu-how-to-use-radcontextmenu-with-radgridview.html
which explains in details how you can use RadGridView with RadContextMenu and if you still experience the issue, please send us a sample project where it can be replicated, so we to be able to research it further.
Regards,
Yana
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>