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
470
automatically fit a field to its longest cell value
posted

Hi,

I'd need to implement an option in a context menu that resizes a field in a way that all cell values are fully visible.

How could this be done?

Best

Oliver

Parents
No Data
Reply
  • 34810
    Offline posted

    Hello Oliver,

    Thank you for your post!

    Fields in the XamDataGrid have a method named PerformAutoSize, which will resize the field to the largest cell value. By creating an implicit Style for LabelPresenter, you can apply a ContextMenu to the header of each XamDataGrid field, as the LabelPresenter represents the header of a field. Then, by using a command on a "Resize" menu item in your context menu and passing in the menu item itself to the command as a parameter, you can create the functionality to resize the field. MenuItem.Parent will give you the ContextMenu, and in this case, ContextMenu.PlacementTarget will give you the LabelPresenter. The LabelPresenter has a Field property associated with it which will return the field it is the header of, so by using LabelPresenter.Field.PerformAutoSize(), you can resize a XamDataGrid field via a context menu.

    I have attached the sample project to demonstrate the above.

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

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    XDGAutoSizeFieldContextMenuCase.zip
Children