DataGrid - last empty column

Jun 19, 2009 at 7:17 PM

If I bind a DataGrid to a collection of a class containing 3 properties I get 3 columns on the grid. But when I resize the grid stretching it, I can see a 4th empty column. How can I make it so that when I strech the grid, the 3rd column get stretched to fill up the space?


Jun 19, 2009 at 7:48 PM

You need to set the width of the last column to * or specify the maximum width of the datagrid itself

Jun 19, 2009 at 8:06 PM

Thanks cheapsaket. In case I don't have column definitions, I assume I cannot set the width of the last column to *. It would make sense if this would be the defult width for the last generated column.

Jul 3, 2009 at 3:54 PM

I think i had the same problem. I had the problem, that I set my datagrid to a fixed width (so when only two columns are added, it does not look so skinny). But then it looked like if i had an extra empty column (took me a while to realize that it was not really a column) :)

Here is how I fixed the problem. The answer above is right, but when adding the columns programatically, try the following:




<font size="2">




int i=1;<font size="2">




foreach (DataGridColumn col in datagrid.Columns)

{<font size="2">

col.Width =


new DataGridLength(i, DataGridLengthUnitType.Star);


this sets the column with to "1*".

Then the columns spanned the whole grid and I did not see an artificial empty column.