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
2090
XamDatagrid: fix some columns
posted

Hello,

I have a XamDatagrid with following setup:

1. Two fix fields on the left end

2. Some variable fields (user can show/hide/move)

3. One fix field

4. A number of code behind generated fields

I would like to get following situation:

a) The two fields on the left side cannot be moved anywhere

b) The variable fields can be moved inside there own space, but before or insde the section a) oder c)

c) The one field cannot be moved moved to any other place

I have already used PreventColumnMove to prevent the move of colums in section a) and c) but cannot manage to get the desired behaviour for section b)

Your feedback is very welcome!

Thanks

Niko

  • 34690
    Offline posted

    Hello Niko,

    I have been investigating into the behavior you are looking to achieve, and while I am rather unsure of the “PreventColumnMove” behavior you are referring to, I believe I have a recommendation for you to achieve “point B” of your requirements.

    Unfortunately, the Field moving in the XamDataGrid is controlled at a FieldLayout level, and so there is no property that you can use to control Field moving on a Field-by-Field level. Instead, my best recommendation in this case would be to use the following Style for LabelPresenter:

    <Style TargetType="{x:Type ig:LabelPresenter}">
       <EventSetter Event="PreviewMouseMove" Handler="LabelPresenter_PreviewMouseMove" />
    </Style>

    In the event handler for LabelPresenter_PreviewMouseMove, you can use something like the following where “Fixed1” would be the Field that you want to prevent the movement of:

            private void LabelPresenter_PreviewMouseMove(object sender, MouseEventArgs e)
            {
                LabelPresenter lp = sender as LabelPresenter;
                if (lp.Field.Name == "Fixed1")
                {
                    e.Handled = true;
                }
            }

    This will still allow you to perform actions like sorting / filtering on the column header while not being able to actually move it.

    I hope this helps. Please let me know if you have any other questions or concerns on this matter.