2012-08-13 36 views
1

我想有能力選擇單元格並選擇行。 爲了選擇單元格,我設置了SelectionUnit =「Cells」和SelectionMode =「Extended」。 它工作正常。但現在我需要有能力選擇行。用戶通過行頭選擇行(位於行的左側)很明顯。如何在點擊行標題時選擇整行?

如何輕鬆實現?

+0

這是組件特定的行爲,我想你會在telerik的論壇上檢查更多的運氣。 – Terry 2012-08-13 09:05:38

+0

你能更詳細地解答你的問題嗎?與您的行標題聲明相混淆?請提供更多詳細信息,以便我可以更好地瞭解您的問題。 – kashyapa 2012-08-13 12:01:03

+0

我已更改問題描述。 – Rover 2012-08-13 12:32:40

回答

3

快速修復:

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; 
     } 
    } 
} 
2

開箱即用的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

+0

可能您是否知道啓用兩種條件的任何解決方法? – Rover 2012-08-14 09:10:50

+0

感謝您的回答。我發現解決方案如何繞過這個限制。 – Rover 2012-08-14 10:34:28

0

只需添加Telerik的當你定義你的列時,gridviewselectcolumn。此列將複選框添加到每個行和標題。通過點擊標題複選框將選擇所有行。

<telerik:RadGridView.Columns> 
<telerik:GridViewSelectColumn HeaderCellStyle="{StaticResource GridViewHeaderCellStyle1}"/> 
<telerik:GridViewDataColumn Header="Column1" HeaderCellStyle="{StaticResource GridViewHeaderCellStyle1}" MinWidth="150" 
                DataMemberBinding="{Binding XYZ}" /> 
</telerik:RadGridView.Columns> 
相關問題