セルを選択して行を選択できるようにしたい。セルを選択するために、SelectionUnit="Cells" と SelectionMode="Extended" を設定しました。それは正常に動作します。しかし今、私は行を選択する能力が必要です。ユーザーが行ヘッダー (行の左側) を介して行を選択することは明らかです。
簡単に実装するには?
セルを選択して行を選択できるようにしたい。セルを選択するために、SelectionUnit="Cells" と SelectionMode="Extended" を設定しました。それは正常に動作します。しかし今、私は行を選択する能力が必要です。ユーザーが行ヘッダー (行の左側) を介して行を選択することは明らかです。
簡単に実装するには?
クイックフィックス:
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;
}
}
}
すぐに使用できる RadGridView は、選択単位を Cells または FullRow のみに設定する機能を提供します。両方の条件を提供することはできません。
SelectionUnit を Cell に、SelectionMode を Extened に設定することで、拡張セル選択を提供できます。
行を選択するには、SelectionUnit を FullRow に変更する必要があります。
これが RadGridView の仕組みです。
ドキュメントの詳細については、この機能に関する次のドキュメントを参照することをお勧めします。
http://www.telerik.com/help/wpf/gridview-selection-basics.html
http://www.telerik.com/help/wpf/gridview-multiple-selection.html
列を定義するときに、telek gridviewselectcolumn を追加するだけです。この列は、各行とヘッダーにチェックボックスを追加します。ヘッダーのチェックボックスをクリックすると、すべての行が選択されます。
<telerik:RadGridView.Columns>
<telerik:GridViewSelectColumn HeaderCellStyle="{StaticResource GridViewHeaderCellStyle1}"/>
<telerik:GridViewDataColumn Header="Column1" HeaderCellStyle="{StaticResource GridViewHeaderCellStyle1}" MinWidth="150"
DataMemberBinding="{Binding XYZ}" />
</telerik:RadGridView.Columns>