RadContextMenu on ListView removing multiple items

2 posts, 0 answers
  1. Henry
    Henry avatar
    4 posts
    Member since:
    May 2006

    Posted 30 Aug 2013 Link to this post

    I have a RadContextMenu on a RadListView with 2 commands.  Add and Remove.  The Add works fine, but when I use the remove a few times, It removes the selected Index item in addition to the one above it.  The Item.text for the listview items are unique and that is how  I am removing them. 

    Help!  I've been fighting this for 3 days.  Still clicking remove on 1 item results in multiple items being removed. 

    A good example of the radMenuItem1_Click event would be very useful.

    Thanks,
    -Henry
  2. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 04 Sep 2013 Link to this post

    Hi Henry,

    I am not sure what might be causing this in your case. Here is a small example which seems works as expected on my end:
    RadContextMenu contextMenu = new RadContextMenu();
     
    public MainForm()
    {
        InitializeComponent();
     
        RadMenuItem menuItem = new RadMenuItem("Delete");
        menuItem.Click += new EventHandler(menuItem_Click);
     
        contextMenu.Items.Add(menuItem);
     
        radListView1.MouseDown += new MouseEventHandler(radListView1_MouseDown);
    }
     
    void menuItem_Click(object sender, EventArgs e)
    {
        foreach (ListViewDataItem item in radListView1.SelectedItems.ToList())
        {
            radListView1.Items.Remove(item);
        }
    }
     
    void radListView1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            contextMenu.Show(radListView1, e.X, e.Y); 
        }
    }

    If you continue experiencing issues, please provide me with a snippet of your code and I will gladly look into it.

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top