【问题标题】:Prevent reordering on Xceed DataGrid防止在 Xceed DataGrid 上重新排序
【发布时间】:2014-06-11 06:16:31
【问题描述】:

我正在尝试取消 xceed 数据网格(社区版)网格 (http://wpftoolkit.codeplex.com/wikipage?title=DataGrid) 中某些列的重新排序/拖放功能

到目前为止,我所做的是监听 PreviewMouseLeftButtonUp / Down 事件。然后我可以在 Down 设置处理 = true 并且用户不能对列执行任何操作(没有排序或任何事情)或在 Up 上检查 IsBeingDragged 是否为真。但是如果我设置 e.Handled 然后,该列将保持拖动模式。我想要做的是取消整个拖动并将列放回原来的位置,或者(如果可能的话)尽可能靠近放置的列。

谁能指导我?

private void ColumnManagerCell_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    // Check that the Original Source is a ColumnManagerCell
   if (sender.GetType() == typeof(Xceed.Wpf.DataGrid.ColumnManagerCell))
   {
       ColumnManagerCell col = sender as ColumnManagerCell;
       if (col.IsBeingDragged)
       {
            // user attempted to move the column to a new location, or to the GroupByControl area
            e.Handled = true;
       }
   }
}

【问题讨论】:

    标签: wpf wpftoolkit


    【解决方案1】:

    来自 Xceed DataGrid 的文档:

    http://doc.xceedsoft.com/products/XceedWpfDataGrid/#Grouping_Data.html

    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
      xmlns:d="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
      xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase">
      <Grid.Resources>
        <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                    Source="{Binding Source={x:Static Application.Current},
                                                      Path=Orders}">
          <xcdg:DataGridCollectionViewSource.SortDescriptions>
            <scm:SortDescription PropertyName="ShipCountry" Direction="Ascending"/>
            <scm:SortDescription PropertyName="ShipCity" Direction="Ascending"/>
          </xcdg:DataGridCollectionViewSource.SortDescriptions>
          <xcdg:DataGridCollectionViewSource.GroupDescriptions>
            <xcdg:DataGridGroupDescription PropertyName="ShipCountry"/>
            <xcdg:DataGridGroupDescription PropertyName="ShipCity"/>
          </xcdg:DataGridCollectionViewSource.GroupDescriptions>
       </xcdg:DataGridCollectionViewSource>
     </Grid.Resources>
     <xcdg:DataGridControl x:Name="OrdersGrid"
                        ItemsSource="{Binding Source={StaticResource cvs_orders}}">      
       <xcdg:DataGridControl.Columns>
         <xcdg:Column FieldName="ShipCountry" VisiblePosition="0"/>
         <xcdg:Column FieldName="ShipCity" VisiblePosition="1"/>
       </xcdg:DataGridControl.Columns>
       <xcdg:DataGridControl.View>
         <xcdg:TableView FixedColumnCount="2" UseDefaultHeadersFooters="False">
           <xcdg:TableView.FixedHeaders>
             <DataTemplate>
               <xcdg:GroupByControl AllowSort="False" AllowGroupingModification="False"/>
             </DataTemplate>
             <DataTemplate>
              <xcdg:ColumnManagerRow AllowSort="False" AllowColumnReorder="False"/>
            </DataTemplate>
          </xcdg:TableView.FixedHeaders>
        </xcdg:TableView>
      </xcdg:DataGridControl.View>
    </xcdg:DataGridControl>
    </Grid>
    

    【讨论】:

    • 但设置 AllowColumnReorder=False 会阻止所有列重新排序。我想要的是除了固定列之外的所有内容都可以重新排序。因此,第 1 列和第 2 列(例如)可能不会被拖到新位置,但第 5 列可能会被放置为第 3 列。我在您的代码中可以看到,这可以防止所有重新排序还是我遗漏了什么?
    猜你喜欢
    • 2020-12-02
    • 2019-06-19
    • 2013-03-21
    • 2018-10-25
    • 2013-09-11
    • 1970-01-01
    • 2010-11-29
    • 2013-07-08
    • 1970-01-01
    相关资源
    最近更新 更多