This is a migrated thread and some comments may be shown as answers.

ContextMenu on ListControl

2 Answers 185 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Juergen Holzer
Top achievements
Rank 2
Juergen Holzer asked on 10 Sep 2010, 02:42 PM
Hello!

I've successfully added a RadContextMenu to my RadListControl and now I want to get the clicked/selected Item in de ListControl.

In fact the appearing RadContextMenu takes focus and prevents the RadListControl giving a SelectedItem, I can't get it.

Does somebody know a property/way to get the RadListDataItem which was clicked to show the ContextMenu?

Will be happy for any solution.
Thanks and regards
Juergen

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 16 Sep 2010, 05:18 PM
Hi Juergen Holzer,

Thank you for writing.

Right clicking an item should not and does not select items in RadListControl. This is the correct behavior and it is by design. I assume that you have associated RadContextMenu with RadListControl. Now in order to get the item that you have right clicked, please consider the following code snippet:
public Form1()
{
    InitializeComponent();
  
    radListControl1.MouseDown += new MouseEventHandler(radListControl1_MouseDown);
}
  
void radListControl1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        RadListVisualItem clickedItem = radListControl1.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
  
        if (clickedItem != null)
        {
            RadListDataItem dataItem = clickedItem.Data;
            // do sth here
        }
    }
  
}

I hope you find this information helpful. If there is anything else I can assist you with, do not hesitate to contact me.

Best wishes,
Stefan
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
Juergen Holzer
Top achievements
Rank 2
answered on 17 Sep 2010, 09:26 AM
Thanks for the answer! This is what I was looking for, but couldn't find the GetElementAtPoint Method.

Thanks for your help and thanks to Telerik team for your great work!

Kind Regards
Juergen
Tags
ContextMenu
Asked by
Juergen Holzer
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Juergen Holzer
Top achievements
Rank 2
Share this question
or