WPF DataGrid: How to reset column width when applying new ItemsSource

Posted by paul on Stack Overflow See other posts from Stack Overflow or by paul
Published on 2010-03-17T09:28:31Z Indexed on 2010/03/17 9:31 UTC
Read the original article Hit count: 715

Filed under:
|

I am using a DataGrid to display details of an item selected in a ListBox. The DataGrid has 3 columns set to Width="Auto".

As different items in the ListBox are selected, the width of the columns in the DataGrid increase as needed in order to display the text. What I want is that the column widths also decrease when the extra width is not needed.

An example. Column 1 normally contains a percent value. However, in some cases it contains a long error message which causes column 1 to widen and push columns 2 & 3 off the screen. When I switch to an item containing normal values, I want column 1 to regain its' normal width and for columns 2 & 3 to be visible again.

What can I do to force the column widths to take the minimum size?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about datagrid