Row right click and contextMenu

4 posts, 1 answers
  1. Vaggelis Charalabakis
    Vaggelis Charalabakis avatar
    5 posts
    Member since:
    May 2010

    Posted 10 Jun 2010 Link to this post

    What i want is to right click on a row of a radGridView then
    rise up a contextmenustip for the user to click a button and get the current row index from the right click

    How can i do this?

  2. Answer
    Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 15 Jun 2010 Link to this post

    Hello Vaggelis Charalabakis,

    Thank you for writing.

    You can replace the default context menu with a custom one in ContextMenuOpenning event. In the menu item Click event handler, you can get the index of the grid's current row, which will be the index of right-clicked row. Please consider the following code:
    void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
    {
        if (this.radGridView1.CurrentRow is GridViewDataRowInfo)
        {
            RadDropDownMenu menu = new RadDropDownMenu();
            RadMenuItem menuItem = new RadMenuItem("Get row index");
            menuItem.Click += new EventHandler(menuItem_Click);
            menu.Items.Add(menuItem);
            e.ContextMenu = menu;
        }
    }
    void menuItem_Click(object sender, EventArgs e)
    {
        int index = this.radGridView1.Rows.IndexOf(this.radGridView1.CurrentRow as GridViewDataRowInfo);
        MessageBox.Show(String.Format("Current row index is: {0}", index));
    }

    I hope this helps. Let me know if you have any other questions.

    Greetings,
    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Rabeeh
    Rabeeh  avatar
    62 posts
    Member since:
    Sep 2007

    Posted 15 Jul 2010 Link to this post

    How can I get the index of the row that the mouse just moved over, I hooked to the event

     

    RowMouseMove it gives me the row but of type GridDataRowElement

     

     

     

    I can get the index of a row of type GridViewDataRowInfo using this.myGrid.Rows.IndexOf(myRow), how can the get the index of the row of type GridDataRowElement or GridRowElement  ???

    Thank you

     

  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 20 Jul 2010 Link to this post

    Hi Rabeeh ,

    Thank you for the question.

    You can get the row info from the particular row element through the RowInfo property:
     
    GridDataRowElement row = e.RowElement;
    int rowIndex = this.radGridView1.Rows.IndexOf(row.RowInfo);

    Hope this is helpful. Let me know if you have any additional questions.

    All the best,
    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
Back to Top