I'm using Q1 2010 RadGridView in an application where I have a context menu that displays options based on the cell value.
It works perfectly when the user clicks on the cell (CurrentCell property is being loaded) and then right click on it to get the context menu. However, I'd like to provide a behavior like excel in which, when the user rightclicks on any cell, it gets selected and the corresponding context menu will consider the actual cell value.
I couldn't find any property like "SelectCellOnMouseRightClick" or workaround that could help me achieve this. Is there a way I can have this behavior in my RadGridView?
My SelectionMode="Extended", as there are other operation that require multiple row selection.
Thanks in advance
15 Answers, 1 is accepted
You can use the approach demonstrated in this demo. Check the code in RadContextMenu_Opened for more info.
All the best,
Vlad
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.
Private Sub RadContextMenu_Opened(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) |
Dim menu As RadContextMenu = DirectCast(sender, RadContextMenu) |
Dim row As GridViewRow = menu.GetClickedElement(Of GridViewRow)() |
If row IsNot Nothing Then |
row.IsCurrent = True |
row.IsSelected = True |
' The following is not neeed 'cause we are in row select mode (left it in in case we ever |
' need it <ccb 6.10.10> |
'Dim cell As GridViewCell = menu.GetClickedElement(Of GridViewCell)() |
'If cell IsNot Nothing Then |
' cell.IsCurrent = True |
'End If |
menu.IsOpen = True ' needed to show the context menu |
Else |
menu.IsOpen = False |
End If |
End Sub |
End Class |
Currently you can force the grid to unselect all rows by clearing the SelectedItems collection (SelectedItems.Clear()). After the selection is cleared you can select the desired row by setting its IsSelected property to true or simply adding its associated data item to the SelectedItems collection.
We will consider your request regarding right-click selection.
Thank you for your feedback.
Best wishes,
Milan
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.
it says that "Could not load file or assembly "GridView" or one of its dependencies...
Please help..
Could you please clear your XBAP cache by executing the following command from your Visual Studio command prompt:
mage -cc
Sincerely yours,
Milan
the Telerik team
same issue...can someone just paste the code example here.
Thanks
XAML:
<
telerikGrid:RadGridView
x:Name
=
"controlGrid"
Grid.Row
=
"0"
ShowGroupPanel
=
"False"
AutoGenerateColumns
=
"True"
IsFilteringAllowed
=
"False"
CanUserDeleteRows
=
"False"
CanUserReorderColumns
=
"False"
CanUserSortColumns
=
"False"
SelectionUnit
=
"Cell"
SelectionMode
=
"Single"
CanUserSelect
=
"True"
CellEditEnded
=
"cellEditEnded"
RowLoaded
=
"gridRowLoaded"
SelectedCellsChanged
=
"gridSelectedCellsChanged"
>
<
telerik:RadContextMenu.ContextMenu
>
<
telerik:RadContextMenu
x:Name
=
"GridContextMenu"
Opened
=
"GridContextMenu_Opened"
>
<
MenuItem
Header
=
"Add Row"
Click
=
"mnuAddRow_Click"
IsEnabled="{Binding
ElementName
=
controlGrid
,
Path
=
IsReadOnly
, Converter={StaticResource InvertedBooleanConverter1}}" />
<
MenuItem
Header
=
"Add Column"
Click
=
"mnuAddColumn_Click"
IsEnabled="{Binding
ElementName
=
controlGrid
,
Path
=
IsReadOnly
, Converter={StaticResource InvertedBooleanConverter1}}" />
<
MenuItem
Header
=
"-"
/>
<
MenuItem
Header
=
"P_roperties..."
Click
=
"mnuCellProperties_Click"
IsEnabled="{Binding
ElementName
=
controlGrid
,
Path
=
IsReadOnly
,
Converter={StaticResource InvertedBooleanConverter1}}" />
</
telerik:RadContextMenu
>
</
telerik:RadContextMenu.ContextMenu
>
</
telerikGrid:RadGridView
>
C#
private
void
GridContextMenu_Opened(
object
sender, RoutedEventArgs e)
{
try
{
RadContextMenu menu = (RadContextMenu)sender;
GridViewCell cell = menu.GetClickedElement<GridViewCell>();
if
(cell !=
null
)
{
cell.IsSelected =
true
;
cell.IsCurrent =
true
;
}
}
catch
(Exception ex)
{
exceptionHandler(ex);
}
}
I am sorry to see that you have been frustrated with the information provided. The link targets WPF version of the examples that (when being posted) used to be in XBAP (i.e. they could be opened directly in IE). You can find the same example for WPF in your local installation or in our Silverlight demos as well (please follow this link(http://demos.telerik.com/wpf/?GridView/RowContextMenu) for a reference).
Furthermore, you can find information for similar scenarios in our forums as well (link1, link2, link3, link4).
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
You can create custom behavior and attach it to each grid you require such functionality for.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
<
telerik:RadGridView
Name
=
"grdMain"
AutoGenerateColumns
=
"True"
IsReadOnly
=
"True"
ItemsSource
=
"{Binding Data}"
SelectionMode
=
"Single"
SelectionUnit
=
"Cell"
ShowColumnHeaders
=
"False"
ShowInsertRow
=
"False"
ShowGroupPanel
=
"False"
MouseRightButtonUp
=
"grdMain_MouseRightButtonUp"
/>
And here is the code-behind:-
private
void
grdMain_MouseRightButtonUp(
object
sender, System.Windows.Input.MouseButtonEventArgs e)
{
var s = e.OriginalSource
as
FrameworkElement;
if
(s
is
TextBlock)
{
var cell = s.ParentOfType<GridViewCell>();
grdMain.SelectedItems.Clear();
cell.IsCurrent =
true
;
cell.IsSelected =
true
;
}
}
Any idea why this is happening?
Could you try clearing the SelectedCells collection instead ? Do you get the same behavior ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
if (grdMain.CurrentCell != null)
{
grdMain.CurrentCell.IsCurrent = false;
grdMain.CurrentCell.IsSelected = false;
}
grdMain.SelectedCells.Clear();
cell.IsCurrent =
true
;
cell.IsSelected =
true
;
grdMain.SelectedCells.Add(new GridViewCellInfo(cell));
Regards,
J.S.
Thanks a lot. That was a useful piece of information, with example. :)