简体   繁体   中英

Why GridControl is creating an extra column/space after execution?

DevExpress UI controls were used for a Windows Presentation Foundation (or WPF) Application and I am trying to fix/Improve it.

Several views in the application include Grids that display sort of some data to the user. The grids look normal in the designer and by normal I mean the number of columns is same as desired. However after application executes, every Grid in every view generates a new column/space - empty unclickable and useless.

I played around with the properties of the Grid and I couldn't seem to get it fixed. AutoGenerateColumns="None" is set for the whole Grid, and nothing suspecious in the properties of every column. I tried looking at DevExpress Documentation but it wasn't helping and it was time consuming. They mention how hiding/displaying stuff works but not auto generating.

How can I prevent that from happening?

View in the compiler: Here

View after execution: Here

Grid XAML:

            <dxg:GridControl x:Name="sessionGrid" SelectedItem="{Binding SelectedSession}" ItemsSource="{Binding Sessions}" AutoGenerateColumns="None" Margin="0,10,0,0" SelectionMode="Row" Grid.Row="2" DesignTimeDataSourceRowCount="15" TouchDown="sessionGrid_TouchDown" MouseDown="sessionGrid_MouseDown" >
            <dxg:GridControl.Columns>
                <dxg:GridColumn x:Name="sessionNameColumn" Header="Name" FieldName="Name" AllowAutoFilter="False" AllowBestFit="True" AllowEditing="False"  AllowConditionalFormattingMenu="False" AllowGrouping="True" AllowMoving="True" MinWidth="5"/>

                <dxg:GridColumn x:Name="sessionTypeColumn" Header="Type" FieldName="Type" AllowAutoFilter="False"  AllowEditing="False"  AllowColumnFiltering="False" AllowConditionalFormattingMenu="False" SortOrder="Ascending" SortIndex="0">
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings HorizontalContentAlignment="Left"/>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn x:Name="sessionToleranceColumn" Header="Tolerance" FieldName="ToleranceFormatted" AllowAutoFilter="False"  AllowEditing="False"  AllowColumnFiltering="False" AllowConditionalFormattingMenu="False"/>
                <dxg:GridColumn x:Name="sessionDateColumn" Header="Date Created" FieldName="DateCreated" AllowAutoFilter="False" AllowColumnFiltering="False" AllowConditionalFormattingMenu="False" AllowEditing="False" RoundDateTimeForColumnFilter="False">
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings DisplayFormat="G" />
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
            </dxg:GridControl.Columns>

            <dxg:GridControl.View>
                <dxg:TableView x:Name="sessionTable" AllowPerPixelScrolling="True" AllowEditing="False" ShowIndicator="False" AutoWidth="True"  AllowColumnMoving="True" AllowResizing="True" AllowSorting="True" IsColumnMenuEnabled="True" EditorShowMode="MouseUpFocused" IndicatorWidth="70" IsGroupFooterMenuEnabled="False" PrintGroupFooters="False" ShowBandsPanel="False" AllowMasterDetail="False" ShowBandsInCustomizationForm="False" AllowColumnFiltering="False" ShowSearchPanelMode="Never" AllowMoveColumnToDropArea="False">
                    <dxg:TableView.ColumnMenuCustomizations>
                        <dxb:RemoveBarItemAndLinkAction ItemName="{x:Static dxg:DefaultColumnMenuItemNamesBase.ColumnChooser}" />
                    </dxg:TableView.ColumnMenuCustomizations>
                </dxg:TableView>
            </dxg:GridControl.View>
        </dxg:GridControl>

.

ATTEMPT:

Here it says that I need to put Width = '*' but the compiler is not allowing me to put it, neither in XAML nor in Column Properties, so I tried hard coding column Width and MinWidth as mentioned Here . However, it's still not working. Error is "Cannot implicitly convert Type System.Windows.GridLength to double"

        private void sessionGrid_Loaded(object sender, RoutedEventArgs e)
    {     
        foreach (DevExpress.Xpf.Grid.GridColumn gridColumn in sessionGrid.Columns)
        {
        // Do something
        gridColumn.MinWidth = ActualWidth;
        gridColumn.Width = new GridLength(1, GridUnitType.Star);
        }
    }

This was fixed by adjusting and unlocking the width of the gridcontrol inside the main grid. However, we couldn't find the exact pattern/cause of the problem. Therefore, it was fixed by trial and error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM