Home Forums WPF controls Xceed DataGrid for WPF Column autosize to content

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

    Supposedly in version 3.0 columns can be set to autosize to fit content.

    Can someone point me where to look at how to do this?

    Thanks

    Justin

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

    Xceed Support
    Member
    Post count: 5658

    To fit the width of a column to its content requires that you call GetFittedWidth and set the value to the Width property of the column. Other options are to set “*” values to the Width property or to set the ColumnStretchMode, which is defined on the TableView class.

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

    User (Old forums)
    Member
    Post count: 23064

    I tried using following code but always get GetFittedWidth as -1, so it’s not worth for me. Is there any other approach we can follow.

     private void AdjustColumnWidth(Xceed.Wpf.DataGrid.DataGridControl grid)
            {
                foreach (Column column in grid.Columns)
                {
                    double width = column.GetFittedWidth();
                    if (width > 0)
                        column.Width = width;
                }
            }

    I can do with looping all columns and and calculating value after completing binding but it will make slow my application.

    Imported from legacy forums. Posted by Mayank (had 949 views)

    Xceed Support
    Member
    Post count: 5658

    When are you attempting to call the GetFittedWidth method? Do you have columns that are not visible?

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

    User (Old forums)
    Member
    Post count: 23064

    Hello Jenny,

    Can you please post some sample code in order to get this working? This is really important for us at this point.

    Also, the piece of code Mayank posted, is this the way to go in your opinion? 

    Thank you for your help,

    Franck

    Imported from legacy forums. Posted by Franck (had 1015 views)

    Xceed Support
    Member
    Post count: 5658

    The following post provides an example: http://xceed.com/CS/forums/post/8222.aspx

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

    User (Old forums)
    Member
    Post count: 23064

    see the following post http://xceed.com/CS/forums/thread/14691.aspx

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

    User (Old forums)
    Member
    Post count: 23064

    This post might help too: http://www3.xceed.com/CS/forums/permalink/25546/25546/ShowThread.aspx#25546

    Imported from legacy forums. Posted by Neo (had 1158 views)

    tchien69
    Participant
    Post count: 1

    1. The 1st 2 Links above get routed to “https://xceed.com/forums/“. The 3rd Link’s Site doesn’t even exist.

    2. I tried calling GetFittedWidth in the DataGridControl.ItemsSourceChangeCompleted Event (to use it to set Column.Width), but GetFittedWidth is returning -1. I’m using AutoCreateColumns, but the Column.Width’s are just a little narrower than what they need to be.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.