ContextMenu on ListControl

3 posts, 1 answers
  1. Juergen Holzer
    Juergen Holzer avatar
    32 posts
    Member since:
    Mar 2010

    Posted 10 Sep 2010 Link to this post

    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. Answer
    Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 16 Sep 2010 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Juergen Holzer
    Juergen Holzer avatar
    32 posts
    Member since:
    Mar 2010

    Posted 17 Sep 2010 Link to this post

    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
Back to Top