Last Column of a dataGrid appears on resizing [lastColumn-1]

176 views Asked by At

I was trying for a few hours to get rid of a "ghost" column that appear on my last Grid when I try to resize it. I know how not to display it, but every time I try to resize it the "unwanted" column appears from nowhere. Is there any solution to keep my [last-1] column resizable (I mean not to use CanUserResize="False") and last column hidden or not to appear when a resize [last-1] column is made?Many Thanks

Because Two DataGrid’s are aligned every time I resize the column of the first DataGrid I receive a space: DataGrid

Here is the XAML. Line 80 solved my problem but then I have other: user can not resize the column obviously enter image description here

2

There are 2 answers

2
karmjit singh On

If you have posted Xaml of your UI would have helped a lot to understand what's wrong. However these are settings I have on the DataGrid and do not get any extra column.

Most important setting is ColumnWidth="*"

<DataGrid
            x:Name="grdSimpleMap"
            Margin="2"
            AutoGenerateColumns="False"
            CanUserResizeColumns="True"
            ColumnWidth="*"
            ItemsSource="{Binding Path=Map}"
            >
</DataGrid>
2
mm8 On

Is there any solution to keep my [last-1] column resizable (I mean not to use CanUserResize="False") and last column hidden or not to appear when a resize [last-1] column is made?

If you want to be able to resize the last column to a smaller width without having an "extra" column to fill the remaining space, you need to shrink the total width of the DataGrid when resizing. You can do this by setting its HorizontalAlignment property to Left:

<DataGrid HorizontalAlignment="Left" ...