Home Forums WPF controls Xceed DataGrid for WPF Column Width Default to size of content

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

    On a WPF GridView, the columns default to the width of their content such that all content is showing. However with the Xceed grid, you have to set the width manually.

    Is there any way to get them to default to the width of their content without having to make the user double click on the separator

    Imported from legacy forums. Posted by nmosafi (had 2853 views)

    Xceed Support
    Member
    Post count: 5658

    There is currently no way to specify to a column that it should automatically take its content’s Width.

    You can work around this by doing this:
    <hr>
    <code>
    foreach( Column column in this.grid.Columns )
    {
    column.Width = column.GetFittedWidth();
    }
    </code>
    <hr>

    By registering to the grid’s Loaded event (if ItemsSource is static), or by placing a Dispatcher call after changes to the ItemsSource property (if dynamic).

    However, I’d like to determine exactly what you need, so I can file the appropriate feature request.

    When the Fitted Width feature (when double-clicking) is triggered, the DataGridControl only consider the items realized ( because of UI Virtualization).

    Do you mean that the Column’s with should always follow the currently visible items width (while scrolling) or just that the Column should initially size at the visible content’s width?

    Imported from legacy forums. Posted by Marcus [Xceed] (had 1095 views)

    User (Old forums)
    Member
    Post count: 23064

    I think all I need is to change the widths after the ItemsSource changes and that should be fine

    Thanks
    Neil

    Imported from legacy forums. Posted by nmosafi (had 5098 views)

    User (Old forums)
    Member
    Post count: 23064

    Has there been any changes or additions regarding setting the column widths to the content width?  I would like to one-time size the columns to the width of the largest content.  That way we deal with the overhead only once and not when we scroll or change the viewport.  I could also see a need for being able to have the column width follow the currently visible items with while scrolling.  I’ve tried various implementations of calling GetFittedWidth() on the columns and setting the column Width property to this value, but I end up calling this too often in order to make sure the visible columns are always sized correctly – thus slowing down the datagridcontrol considerably (mostly scrolling). 

    Thanks,

    Jared

    Imported from legacy forums. Posted by Jared (had 500 views)

    Xceed Support
    Member
    Post count: 5658

    Version 3.0 adds starrable (*) column widths and the column-stretching feature (TableView.ColumnStretchMode property). There have not been any modifications made in regards to the GetFittedWidth method.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 309 views)

    User (Old forums)
    Member
    Post count: 23064

    Resizing on scroll should not affect performance much if you use the scroll bar. It only calls the getfittedwidth for the columns on mouseup event. So it really isnt being called all that often.

    Imported from legacy forums. Posted by justin (had 2320 views)

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