3 Answers, 1 is accepted
0
Hi Mohan,
Thank you for writing.
When you right click a row in RadGridView it will automatically be selected, so your condition will always be satisfied and the context menu will always be opened. However, for your convenience, here is how to access the clicked row and its properties while opening the context menu:
I hope that you find this information useful.
All the best,
Stefan
the Telerik team
Thank you for writing.
When you right click a row in RadGridView it will automatically be selected, so your condition will always be satisfied and the context menu will always be opened. However, for your convenience, here is how to access the clicked row and its properties while opening the context menu:
void
radGridView1_ContextMenuOpening(
object
sender, ContextMenuOpeningEventArgs e)
{
GridDataCellElement dataCell = e.ContextMenuProvider
as
GridDataCellElement;
if
(dataCell !=
null
)
{
e.Cancel = !dataCell.RowInfo.IsSelected;
}
}
I hope that you find this information useful.
All the best,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Curtis
Top achievements
Rank 2
answered on 10 Sep 2013, 03:11 PM
Hey there,
Wanted to thank you for including this code snippet - it took a little bit to find the solution for my issue.
Although the row is selected upon the right-click action, there are still cases where you need to use the code provided. An example is when you only want to modify the context menu for a given row type (i.e. you only want to modify the context menu for data rows and not filter/header rows). With this code, I was able to compare the type of e.ContextMenuProvider to only modify the context menu for data rows. This could easily be modified to be able to only modify context menus for other types such as header rows, filter rows and new rows.
Thanks again!
Wanted to thank you for including this code snippet - it took a little bit to find the solution for my issue.
Although the row is selected upon the right-click action, there are still cases where you need to use the code provided. An example is when you only want to modify the context menu for a given row type (i.e. you only want to modify the context menu for data rows and not filter/header rows). With this code, I was able to compare the type of e.ContextMenuProvider to only modify the context menu for data rows. This could easily be modified to be able to only modify context menus for other types such as header rows, filter rows and new rows.
Dim
menuItem
As
RadMenuItem =
Nothing
Dim
menuSeperator
As
RadMenuSeparatorItem =
Nothing
' modify the context menu of grid view data rows (i.e. not the header/filter/etc. rows)
If
TypeOf
e.ContextMenuProvider
Is
GridDataCellElement
Then
If
e.ContextMenu.Items.Count > 0
Then
menuSeperator =
New
RadMenuSeparatorItem
e.ContextMenu.Items.Add(menuSeperator)
End
If
menuItem =
New
RadMenuItem(
"View BOM"
)
AddHandler
menuItem.Click,
AddressOf
OnContextMenuClicked_ViewBom
e.ContextMenu.Items.Add(menuItem)
menuItem =
New
RadMenuItem(
"Edit BOM"
)
AddHandler
menuItem.Click,
AddressOf
OnContextMenuClicked_EditBom
e.ContextMenu.Items.Add(menuItem)
End
If
Thanks again!
0
You are most welcome. Let us know if you have any other questions.
Regards,
Stefan
Telerik
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 >>
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 >>