I have a DataGrid which gets its data from an sql table. I have set AutoGenerateColumns to true.
When I click a button the data in the DataGrid is exported to a pdf-file.
However when the width of all columns combined in the DataGrid is bigger than about 800 the table is bigger than the page inside the pdf.
I have set the DataGrid’s MaxWidth-Property to 800. When I resize a column I can drag the cursor outside of the DataGrid and a horizontal scrollbar appears.
Is there a way to limit the maximum size of all columns combined to 800 so that I can not make the column bigger than the DataGrid?
The easy solution is to make the DataGrid use starsizing for its columns by simply setting the ColumnWidth property like this:
The problem however, is that this makes all columns equally wide, which is probably not desired.
So what I would do, is to first create all columns the default way like you do now, and then set each column to a starsize afterwards. That way a value can be calculated for the new width, that makes the column keep its initial size.
I have written a small piece of code, to show what i mean..
XAML
Code-behind