This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Sometimes it's conveninet to be able to auto-size a column. However, I got some feedback from users that say that when the columns continue to auto-size as they scroll up and down it is both distracting and slows down the grid a lot. Is it possible to have a columns autosize just once when the data initialliy displayed, but therefter not continue to autosize. If not currently possible this would be an appreciated feature. Peter |
|
|
Hello Peter In the next nightly build you will find the DataGrid will have a new AutoColumnWidthBehavior property. Set this to OneTime for the columns to only be auto measured once when the DataGrid is loaded, or when the ItemsSource property changes. Note that when using this option, the width of the columns will only consider the visible rows at load time. Considering all rows would have a massive performance impact. Jason Fauchelle |
|
|
Hi Jason, Thanks for your quick response. However, the new one-time behavior is generally not working correctly for me. I am using auto-width for the first column only, and as usual (for me) I am setting up the grids in code, and always set up the columns first before setting the ItemsSource. I am seeing either of two problems: 1) In some cases the first column appears to be sized based on the header only. Other columns are fine. 2) In other cases the first column appears to be sized correctly but the header width of the LAST column is less than the cells in the last column (weird!), and the cell borders in the column can be lost for wide content. In every case in my program where I have tried the one-time auto width I am getting one of these two problems. I made a demo project, but am only able to reproduce the second problem--but that's better than nothing so I am attaching it. When you run the project you can select which columns are auto-width, and maybe change the column headers, then click Setup Grid to build the grid. Here is what I am seeing In the initial state (column 1 is auto-width, and headers are "Value", "Squared" and "Cubed"), click Setup Grid => grid is fine. Change column 2 to auto-width, click Setup Grid => column header 3 is messed up. Also scroll down and observe cell borders are messed up too. I find that with most combinations column header 3 is messed up, except when no columns are auto-width, or just the first column is auto-width (this contradicts results in my actual program). Now select column 1 only to be auto-width and clear the header for column 1, click Setup Grid => column 3 header is messed up. So the header content can be a factor here. By the way, I am using framework 4.0. A couple of other related wishes: 1) It would be nice to have something like a MaxAutoWidth property on columns that limits how wide a column could be made by auto width, since sometimes content might be wider than is reasonable to accommodate with auto-width. 2) I generally use a header template that allows headers to wrap, so in such cases it would be better not to consider the header width in determining the column auto width. So it would be nice to have an option to not consider header width in calculating the auto-width. Peter |
|
|
Hello Peter Thanks for pointing out these bugs and sending us the repro project. The bugs demonstrated in the repro will be resolved in the next nightly build. I was unable to reproduce the first bug you mentioned. If this is still an issue in the next nightly build, please give us more information about how to reproduce this issue so we can solve it. In the next nightly build you will also find DataGridColumn now has a MaxAutoWidth property, and DataGrid has a new CanAutoSizeColumnHeaders property. Jason Fauchelle |
|
|
Hi Jason, Thank you for the updates. I see that the second bug is fixed. The first problem is still present. I will see if I can provide more information. I did find that using the CanAutoSizeColumnHeaders property results in the headers of the autosize columns being messed up. You can observe this in the same demo project I sent in my previous post by setting the CanAutoSizeColumnHeaders to false (either in XAML or code). Peter |
|
|
Hi Jason, I observed an unrelated problem while using Snoop (my favorite WPF debug tool), but since you can also observe this problem with the same demo project (if you have Snoop) it seems better to tack this issue on to this thread rather than starting a new one. When I try to use Snoop by hovering the mouse over a text cell while pressing Crtl-Shift I always get un unhandled exception because in DataGrid.OnMouseMove the mouseOverObject is a System.Windows.Documents.Run, which is not a visual, but it gets passed to VisualTreeUtils.FindContaining Peter |
|
|
Hi Jason, While I still can't reproduce my original problem in my simple demo, I can reproduce another problem which might be related. Run the attached project, which is the same as the previous project except I have added a few columns and changed the first column text. Click the SetupGrid button. Observe that while the columns are displayed correctly the horizontal scroll bar is sized incorrectly, which you can verify by scrolling over to the right (lots of extra white space to the right of the grid, and header area above whitespace is messed up). Now check the check box labelled "36", and click Setup Grid again. Observe the horizontal scroll bar is now sized correctly. The only thing this changes is a single text value in the value column. If you make the window wider so all columns can fit and click Setup Grid again then everything is fine (whether 36 is checked or not) I have some other clues from my actual project. My table that has the problem with auto-sizing the first column (others are not auto) has more columns than fit in the normal width window. However, if I make the window extra wide so all columns will fit, then when the table is created the first column auto-sizes fine. Also, in the debugger I am able to observe that when the column auto-sizes incorrectly it's AutoWidth property does get set to the correct value (based on the widest cell), but then gets reset to zero, in DataGridPanel.MeasureOverride, and then gets set to the width based on the header only and does not re-check the cells, which results in my observed problem (when it sizes correctly it then rechecks all the cell in the second pass as well). I hope this helps Peter |
|
|
Hello Peter Thanks for all the information and the repro project. Setting CanAutoSizeColumnHeaders to false will no longer mess up the header displays. I also use Snoop and had come across this exception but didn't think anything of it. Since you use Snoop to aid in debugging the DataGrid, I've resolved this exception. I've also resolved the issue that causes the extent-width of the data grid to be larger than it should be. These fixes will be available through the next nightly build. Let me know if the original problem has not been resolved by any of these fixes. Jason Fauchelle |
|
|
Hi Jason, The latest build does seem to resolve all problems mentioned in this thread, including the original column sizing problem that I could never reproduce in my demo project. Thanks for the continued great support. Peter |
|