Home Forums WPF controls Xceed DataGrid for WPF Reordering Column Visible Position

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #23856 |

    I have created a grid where the columns are effectively in pairs. I would like to be able to allow the users to reorder the columns by drag/drop of the header.

    The built in logic works fine for single columns, but obviously not for pairs of columns where I want the other pair to also move.

    I have used the following code to be notified of the chnage of the VisibleIndex property for each column:

    DependencyPropertyDescriptor myDescriptor = DependencyPropertyDescriptor.FromProperty(Column.VisiblePositionProperty, typeof(Column));

    myDescriptor.AddValueChanged(column, new EventHandler(MyColumnVisiblePositionChangedHandler));

    This is triggered whenever the VisiblePosition property changes, but this also includes the columns that are moved to make room for the one that I am interested in.

    Does anyone have any hints/ideas for how to correctly identify which column was moved by the user so that I can move its pair column in code.

    Imported from legacy forums. Posted by Derek (had 867 views)

    User (Old forums)
    Member
    Post count: 23064

    Possibly helpful info from post 8460:

    http://forums.xceed.com/forums/ShowPost.aspx?PostID=8460


    For the Column re-ordering, you could observe the DataGridControl’s VisibleColumns collection.

    Imported from legacy forums. Posted by Richard (had 286 views)

    User (Old forums)
    Member
    Post count: 23064

    Unfortunately this does not do it for me.

    Observing the VisibleColumns collection I see that its contents are Reset when the column drop event happens and then each visible column is added to the collection.

    Hence it does not really give me any more information than I have when I get notified that the VisiblePositionProperty changed.

    Any other ideas?

    Imported from legacy forums. Posted by Derek (had 410 views)

    User (Old forums)
    Member
    Post count: 23064

    One idea that comes to mind is to use a single column that combines the information from the two fields in question. You could use a Column.CellContentTemplate to layout the information in a double column format and create specialized cell editor to allow the user to update it. You could consider control sorting details with a context menu and/or grid header/footer radio buttons.

    I realize this isn’t what you want to do, but it may be a different way to think about it.

    Here’s a snippet of code from a test project where I was playing around with this idea a while ago:

    <code>

    <xcdg:Column FieldName=”CurrentAddress” DisplayMemberBinding=”{Binding Path=CurrentAddress, Mode=TwoWay}” Title=”Address” MinWidth=”200″
    CellEditor=”{x:Static local:XceedDataGridCellEditorHelpers.AddressComboBoxCellEditor}”>
    <xcdg:Column.CellContentTemplate>
    <DataTemplate>
    <StackPanel Orientation=”Vertical”>
    <StackPanel.Resources>
    <Style TargetType=”TextBlock”>
    <Setter Property=”Margin” Value=”2″/>
    </Style>
    </StackPanel.Resources>
    <TextBlock FontStyle=”Italic” Text=”{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:DataCell}}, Path=DataContext.CurrentAddress.Street}” />
    <TextBlock FontStyle=”Italic” Text=”{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:DataCell}}, Path=DataContext.CurrentAddress.City}” />
    <TextBlock FontStyle=”Italic” Text=”{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:DataCell}}, Path=DataContext.CurrentAddress.State}” />
    </StackPanel>
    </DataTemplate>
    </xcdg:Column.CellContentTemplate>

    </code>

    Imported from legacy forums. Posted by Richard (had 4162 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.