Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
Cannot Change Column Position after using SplitterBar to pin columns
posted

My datasource is a list of entities containing 6 fields. This is bound to a XamDataGrid, which has a splitter bar and pins on the columns to fix/pin the columns.

Here is the entity
    public class Entity
    {
        public int Col1 { get; set; }
        public int Col2 { get; set; }
        public int Col3 { get; set; }
        public int Col4 { get; set; }
        public int Col5 { get; set; }
        public int Col6 { get; set; }
    }

and the XamDataGrid is defined in the xaml like
<igDP:XamDataGrid Name="Sample" >
    <igDP:XamDataGrid.FieldSettings>
        <igDP:FieldSettings AllowFixing="Near" />
    </igDP:XamDataGrid.FieldSettings>
    <igDP:XamDataGrid.FieldLayoutSettings>
        <igDP:FieldLayoutSettings FixedFieldUIType="ButtonAndSplitter" AutoGenerateFields="True" />
    </igDP:XamDataGrid.FieldLayoutSettings>
</igDP:XamDataGrid>

When I use the drag the splitter bar till Col5 in order to pin the columns, the ActualPosition of the columns visible changes from

Col1(unpinned), Col2(unpinned), Col3(unpinned), Col4(unpinned), Col5(unpinned), Col6(unpinned)
to
Col5(pinned), Col1(pinned), Col2(pinned), Col3(pinned), Col4(pinned), Col6(unpinned)
I think this might be expected behavior, so I decided to programmatically rearrange the columns back to
Col1(pinned), Col2(pinned), Col3(pinned), Col4(pinned), Col5(pinned), Col6(unpinned)

I tried the code below and placed it at the end of FieldPositionChanging, FieldPositionChanged and LayoutUpdated events in the XamDataGrid. The events get fired and the code gets executed, however the columns do not rearrange. Any ideas? Thanks in advance.


bool rearranged = false;
foreach (Field fs in Sample.DefaultFieldLayout.Fields)
{
    if (fs.ActualPosition.Column != fs.Index)
    {
        rearranged = true;
        break;
    }
}

if (rearranged)
{
    for (int i = 0; i < Sample.DefaultFieldLayout.Fields.Count; i++)
    {
        Field fs = Sample.DefaultFieldLayout.Fields[i];
        if (fs.ActualPosition.Column != fs.Index)
            Sample.DefaultFieldLayout.Fields.Move(fs.ActualPosition.Column, fs.Index);
    }
}

  • 54937
    Verified Answer
    Offline posted

    Alex is right about the customization. Once you customize the layout the order of the fields within the Fields collection is not used. Move just changes the index of the Field within the Fields collection. Relatively recently we had added a settable ActualPosition property on the Field that can be used to get/set the current displayd position of the field. That being said dragging the fixed field splitter over the first 5 fields should retain the order of the fieldsl I tested this out and it seems to work as expected:

     

  • 69686
    Verified Answer
    posted

    I believe, this action will be considered a customization made by the user and the Move method of the Fields collection will not be reflected. However, calling the ClearCustomizations(...) method of the XamDataGrid will clear this and return back to the default state.

    Moreover, you can also use the Undo/Redo functionality of the XamDataGrid if you are using volume 9.2. You can see a similar example of this in the XamFeatureBrowser - XamDataGrid - Layout and Behavior - Undo (simple)