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

Row right click and contextMenu

3 Answers 1099 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vaggelis Charalabakis
Top achievements
Rank 1
Vaggelis Charalabakis asked on 10 Jun 2010, 10:20 AM
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?

3 Answers, 1 is accepted

Sort by
0
Accepted
Martin Vasilev
Telerik team
answered on 15 Jun 2010, 04:39 PM
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.
0
Rabeeh
Top achievements
Rank 2
answered on 15 Jul 2010, 01:18 PM

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

 

0
Martin Vasilev
Telerik team
answered on 20 Jul 2010, 05:45 PM
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
Tags
GridView
Asked by
Vaggelis Charalabakis
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Rabeeh
Top achievements
Rank 2
Share this question
or