Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill width of last column at DevExpress GridControl?

I have DevExpress GridControl wich has 7 columns. I tried to expand the last column to the right, but nothing happens. Instead, the column stretches for some distance, and on the right edge of the grid, there is an empty column with no name, which can not be stretched.

So, I try to google it: I find some answers like this, but it does not work for me.

Here some peace of XAML, I remove all bindings.

<dxg:GridControl Grid.Row="0"
                x:Name="dgGrid"
                VerticalAlignment="Stretch"
                HorizontalAlignment="Stretch"
                dx:ThemeManager.ThemeName="Seven"

                ScrollViewer.CanContentScroll="True"
                ScrollViewer.HorizontalScrollBarVisibility="Auto"
                ScrollViewer.VerticalScrollBarVisibility="Auto"
                >

    <dxg:GridControl.View>
        <!--region #RowCellMenuCustomization-->
        <dxg:TableView x:Name="view" AutoWidth="True" NavigationStyle="Cell">
            <dxg:TableView.RowCellMenuCustomizations>
                <dxb:BarButtonItem Content="Link"
                                ItemClick="CellDataItem_Link_ItemClick"
                                ></dxb:BarButtonItem>

                <dxb:BarButtonItem Content="UnLink"
                                ItemClick="CellDataItem_UnLink_ItemClick"
                                ></dxb:BarButtonItem>
            </dxg:TableView.RowCellMenuCustomizations>
        </dxg:TableView>
        <!--endregion #RowCellMenuCustomization-->
    </dxg:GridControl.View>

    <dxg:GridControl.Columns>

        <dxg:GridColumn Header="Column0"
                    AllowEditing="False"
                    HorizontalHeaderContentAlignment="Stretch"
                    FixedWidth="True"
                    AllowResizing="True"
                    MinWidth="80"
                    ></dxg:GridColumn>

        <dxg:GridColumn Header="Column1"
                    AllowEditing="False"
                    HorizontalHeaderContentAlignment="Stretch"
                    FixedWidth="True"
                    AllowResizing="True"
                    MinWidth="80"
                    ></dxg:GridColumn>

        <dxg:GridColumn Header="Column2"
                    AllowEditing="False"
                    HorizontalHeaderContentAlignment="Stretch"
                    AllowResizing="True"
                    FixedWidth="True"
                    Visible="False"
                    MinWidth="80"
                    ></dxg:GridColumn>

        <dxg:GridColumn Header="Column3"
                    HorizontalHeaderContentAlignment="Center"
                    AllowEditing="False"
                    Width="35"
                    FixedWidth="True"
                    AllowResizing="False"
                    ></dxg:GridColumn>

        <dxg:GridColumn Header="Column4"
                    HorizontalHeaderContentAlignment="Center"
                    FixedWidth="True"
                    AllowEditing="False"
                    AllowResizing="False"
                    Width="35"
                    ></dxg:GridColumn>

        <dxg:GridColumn Header="Column5"
                    HorizontalHeaderContentAlignment="Stretch"
                    FixedWidth="True"
                    AllowEditing="False"
                    AllowResizing="True"
                    MinWidth="170"
                    ></dxg:GridColumn>

        <dxg:GridColumn Header="Column6"
                    HorizontalHeaderContentAlignment="Stretch"
                    AllowEditing="False"
                    AllowResizing="True"
                    Width="*"
                    Fixed="None"
                    BestFitMode="Default"
                    BestFitArea="All"
                    MinWidth="130"
                    FixedWidth="False"
                    />

    </dxg:GridControl.Columns>
</dxg:GridControl>

Here example of my GridControl

At the same time, I use BestFit method, which works when GridControl loaded:

private void Grid_Loaded(object sender, RoutedEventArgs e)
{
    ((TableView)this.view).BestFitArea = BestFitArea.All;
    var visibleColumns = ((TableView)this.view).VisibleColumns;
    ((TableView)this.view).BestFitColumns();
}

Please, can you help me to fit last column (Column6) width to the end of the grid?

like image 797
Admiral Land Avatar asked May 25 '17 11:05

Admiral Land


1 Answers

TableView.AutoWidth property is what you are looking for. You have already set it, but there is error in your Column6. The Width of column cannot be set to "*". So, I used your code, removed Width="*" and here is the result:

Result

like image 200
nempoBu4 Avatar answered Sep 23 '22 04:09

nempoBu4