
Any tips on how to enable selection of a GridViewRow from a right mouse click?
There are plenty of examples demostrating how to do this when a ContextMenu is involved, but I do now want a ContextMenu in my case.
Thanks in advance!
Regards,
Roland
11 Answers, 1 is accepted
You could select a row on a right mouse click after you subscribe for the MouseRightButtonUp event of the RadGridView. Then you should check where you have clicked. If you have clicked on a row, then mark the clicked row as selected.
private
void
clubsGrid_MouseRightButtonUp(
object
sender, MouseButtonEventArgs e)
{
var s = e.OriginalSource
as
FrameworkElement;
if
(s
is
TextBlock)
{
var parentRow = s.ParentOfType<GridViewRow>();
if
(parentRow !=
null
)
{
parentRow.IsSelected =
true
;
}
}
}
I believe that this is what you are looking for.
Regards,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>


Is there any way to do this in MVVM way. There are older post which give solution to attach a behaviour. But their links are not getting open.
Please can you share a attach behaviour to solve this problem in MVVM way.
Thanks,
Fatema
Actually our official demo is using attached behavior. You can find the same example in your local copy of our WPF demos as well.
Regards,Vlad
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

In the demo context menu is used i want to apply select row on right mouse button click.
I am sorry but i am not able to find a demo for this.
Regards,
Fatema
The code is virtually the same. You need however MouseRightButtonUp instead ItemClick of the menu.
All the best,Vlad
the Telerik team
Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Can I do something about this to make it work, or is this a bug?
In this forum thread there is a discussion how to select a row when the user clicks the right mouse button. As I understand you would like to unselect a row. How have you implemented the deselection?
Do you experience the same result if the SelectionMode is Single or Multiple?
Didie
Telerik
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 >>

Thanks for your reply. In the meantime I have solved this issue. When using the SelectionMode="Extended" I wasn't aware of the fact that I had to (select and) deselect every selected row myself.
I solved it like this:
void
RadGridViewMouseRightButtonUp(
object
sender, System.Windows.Input.MouseButtonEventArgs e)
{
var s = e.OriginalSource
as
FrameworkElement;
var parentRow = s.ParentOfType<GridViewRow>();
if
(parentRow !=
null
)
{
//When the SelectionMode of the RadGridView is extended, then the SHIFT and
//CTRL key has to be checked. When they are not pressed the selection is cleared,
//and only the given row is selected (this works like this for the Extended and
//Single SelectionMode).
if
(Keyboard.IsKeyDown(Key.LeftShift) ==
true
||
Keyboard.IsKeyDown(Key.RightShift) ==
true
||
Keyboard.IsKeyDown(Key.LeftCtrl) ==
true
||
Keyboard.IsKeyDown(Key.RightCtrl))
{
parentRow.IsSelected =
true
;
}
else
{
_radGridView.SelectedItems.Clear();
parentRow.IsSelected =
true
;
}
}
}
I am glad to hear you managed to resolve the issue.
Regards,Didie
Telerik
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 >>
Hello,
A short follow up on this topic. Setting local values on GridViewRow (or GridViewCell) properties is not recommended, unless the UI virtualization is disabled. Note that the virtualization is enabled by default and disabling it will slow down the control quite a lot.
Instead, use data bindings for setting the cell or row properties. You can do this via the RowStyle property of RadGridView or CellStyle of the column objects. Also, you can use implicit styles instead of the style properties.
For the selection matter, use the SelectedItem or SelectedItems property of RadGridView. You can read how to select an item in code, in the Programmatic Selection help article. Here is also an example in code, based on the last code snippet in this forum:
void RadGridViewMouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
var s = e.OriginalSource as FrameworkElement;
var parentRow = s.ParentOfType<GridViewRow>();
if (parentRow != null)
{
var dataItem = (MyRowModel)parentRow.Item;
if (Keyboard.IsKeyDown(Key.LeftShift) ||
Keyboard.IsKeyDown(Key.RightShift) ||
Keyboard.IsKeyDown(Key.LeftCtrl) ||
Keyboard.IsKeyDown(Key.RightCtrl))
{
radGridView.SelectedItems.Add(dataItem);
}
else
{
_radGridView.SelectedItems.Clear();
radGridView.SelectedItems.Add(dataItem);
}
}
}
Regards,
Martin Ivanov
Progress Telerik