Reputation: 2230
I want to have ability select cells and select rows. For selecting cells I've set SelectionUnit="Cells" and SelectionMode="Extended". It works fine. But now I need in ability to select rows. It's clear for user to select rows via rows headers (at the left part of row).
How to implement it easily?
Upvotes: 1
Views: 2042
Reputation: 557
Just add telerik gridviewselectcolumn when you define your columns. This column adds checkbox to each rows and header. By Clicking on the header checkbox will select all rows.
<telerik:RadGridView.Columns>
<telerik:GridViewSelectColumn HeaderCellStyle="{StaticResource GridViewHeaderCellStyle1}"/>
<telerik:GridViewDataColumn Header="Column1" HeaderCellStyle="{StaticResource GridViewHeaderCellStyle1}" MinWidth="150"
DataMemberBinding="{Binding XYZ}" />
</telerik:RadGridView.Columns>
Upvotes: 0
Reputation: 2230
Quick fix:
private void RadGridView_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if(e.RightButton == MouseButtonState.Pressed)
return;
var source = e.OriginalSource as DependencyObject;
if(source == null)
return;
var cell = source.FindVisualParent<GridViewCell>();
if(cell != null)
{
((RadGridView)sender).SelectionUnit = GridViewSelectionUnit.Cell;
}
else
{
var row = source.FindVisualParent<GridViewRow>();
if(row != null)
{
((RadGridView)sender).SelectionUnit = GridViewSelectionUnit.FullRow;
}
}
}
Upvotes: 5
Reputation: 1626
The RadGridView out of the box will provide you the feature to set the selection units to either Cells or FullRow only. It cannot provide you with both conditions.
You are able to provide extended cell selection by setting the SelectionUnit to Cell and SelectionMode to Extened.
Now in order to make the row selection you will have to change the SelectionUnit to FullRow.
This is how the RadGridView works.
For more information documentation i suggest you to have a look at the following documentation on this feature:
http://www.telerik.com/help/wpf/gridview-selection-basics.html
http://www.telerik.com/help/wpf/gridview-multiple-selection.html
Upvotes: 3