[C1DataGrid] How to resize the column but does not change the width of dataGrid

Posted by: transonchien3010 on 25 July 2018, 2:12 pm EST

    • Post Options:
    • Link

    Posted 25 July 2018, 2:12 pm EST

    When resize any column. I want another column to automatically shrink the width. When it will not appear HorizontalScrollBar and width of datagird unchanged.

    You can see video examples below for better understanding.

    https://drive.google.com/file/d/1mCYFF8evOxc3ntG9vX1h9ObOqJqaM4LX/view?usp=sharing

    Tks you.

  • Posted 29 July 2018, 5:23 pm EST

    Hello,

    First of all, apologies for the time taken in responding to you.

    Reg, the requirement, if you set Width of all columns to * then you should be get a behavior pretty close to the one shown in your video. The difference would be: When resizing a column, if all remaining columns have achieved their MinWidth (showing …) and then if the user tries to further extend the column, C1DataGrid would allow that whereas, in your video, it looks like extending beyond it is not possible/allowed. This is the design behavior of C1DataGrid.

    However, if you wish to prevent that too, you need to manually handle the ColumnResizing event and calculate the width for all columns then compare the values and accordingly set MaxWidth for that column, as follows:

            private void _grid_ColumnResizing(object sender, C1.WPF.DataGrid.DataGridColumnEventArgs e)
            {
                totalWidth = 0;
                foreach (C1.WPF.DataGrid.DataGridColumn col in _grid.Columns)
                {
                    if (col != e.Column)
                    {
                        totalWidth += col.ActualWidth;
                        col.MaxWidth = Double.MaxValue;
                    }
                }
                if (_grid.ActualWidth <= (totalWidth + e.Column.ActualWidth +25 ))
                    e.Column.MaxWidth = e.Column.ActualWidth;
                else
                    e.Column.MaxWidth = Double.MaxValue;
            }
    
    ```I also attached a demo application for this purpose.
    
    Regards,
    Ruchir
    [zip filename="ColumnWidth_C1DataGrid.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-069462b9-3db6-4cad-b2de-0da0e20f6505.zip[/zip]
  • Posted 29 July 2018, 6:55 pm EST

    Hi Ruchir.agarwal,

    It is an idea, however your demo is false .

    You can help me one better idea ? or modify your example to be true for video.

    Link video : https://drive.google.com/file/d/1mCYFF8evOxc3ntG9vX1h9ObOqJqaM4LX/view?usp=sharing

    This is the code set column in my project. You can use it for your sample.

    
    <c1:C1DataGrid AllowDrop="True"
                                                           AlternatingRowBackground="White"
                                                           AutoGenerateColumns="False"
                                                           CanUserReorderColumns="False"
                                                           CanUserSort="False"
                                                           ItemsSource="{Binding Path=SystemAccountModels}"
                                                           RowHeaderWidth="0"
                                                           SelectedItem="{Binding Path=SelectedSystemAccountModel, Mode=TwoWay}"
                                                           SelectionMode="SingleRow"
                                                           ShowGroupingPanel="False">
    
                                                <!--  ビヘイビア(ドロップ・ダブルクリック・オートスクロール)  -->
                                                <c1:C1DataGrid.RowStyle>
                                                    <Style TargetType="c1:DataGridRowPresenter">
                                                        <Setter Property="AllowDrop" Value="True" />
                                                    </Style>
                                                </c1:C1DataGrid.RowStyle>
    
                                                <!--  グリッドビューの列設定  -->
                                                <c1:C1DataGrid.Columns>
                                                    <c1:DataGridTextColumn Width="Auto"
                                                                           Binding="{Binding Path=No}"
                                                                           Header="No." />
    
                                                    <!--  システム科目列(名称)  -->
    
                                                    <c1:DataGridTextColumn Width="Auto"
                                                                           Binding="{Binding Path=SystemAccount.Label}"
                                                                           Header="システム科目" />
    
                                                    <!--  システム科目列(開示科目)  -->
                                                    <c1:DataGridTemplateColumn Name="NodeModel.Code"
                                                                               Width="*"
                                                                               Header=" ">
                                                        <c1:DataGridTemplateColumn.CellTemplate>
                                                            <DataTemplate>
                                                                <wicCon:LabelExtension Content="{Binding Path=NodeModel.Code}" ContentChanged="{Binding Path=IsEdited}" />
                                                            </DataTemplate>
                                                        </c1:DataGridTemplateColumn.CellTemplate>
                                                    </c1:DataGridTemplateColumn>
    
                                                    <!--  関連付けられた開示科目情報  -->
                                                    <c1:DataGridTemplateColumn Width="2*" Header="関連付けられた開示科目情報">
                                                        <c1:DataGridTemplateColumn.CellTemplate>
                                                            <DataTemplate>
                                                                <wicCon:LabelExtension Content="{Binding Path=DisclosureName}" ContentChanged="{Binding Path=IsEdited}" />
    
                                                            </DataTemplate>
                                                        </c1:DataGridTemplateColumn.CellTemplate>
                                                    </c1:DataGridTemplateColumn>
    
                                                </c1:C1DataGrid.Columns>
                                            </c1:C1DataGrid>
    
    

    Thank you very much.

  • Posted 29 July 2018, 7:13 pm EST

    5 days have passed . I need your support .

  • Posted 31 July 2018, 2:43 pm EST

    Hi Ruchir.agarwal,

    Because of privacy, I do not share my app with you. However, I have customized your demo. In columns 1 and 2 I have set width = Auto, column 3 set width=“" and column 4 set width="2”.

    When I run your demo it is not stable, some cases still appear HorizontalScrollBar when resizing , and resize is bigger than ActualWidth of DataGrid.

    You can help me fix it?

    Thanks & regards,

    ColumnWidth_C1DataGrid.zip

  • Posted 31 July 2018, 3:02 pm EST

    Hello,

    Did you try running the sample I shared? It’s working at my end.

    Also, as mentioned in the response earlier, for the approach to work you need to set Width to *. But your XAML code shows the Width set to Auto for few columns. Could you try to do that?

    However, if still you are facing issues implementing the same in your application, could you please share your application or its stripped version !

    Thanks & regards,

    Ruchir

  • Posted 9 August 2018, 12:48 am EST

    Hi,

    I am discussing your requirement [ID: 338134] with the concerned team and will update you with the solution/information we receive.

    ~Ruchir

  • Posted 9 August 2018, 12:49 am EST

    Hi,

    I am discussing your requirement with the concerned team [ID: 338134] and will update you once we have a solution for your requirement.

    ~Ruchir

  • Posted 12 August 2018, 7:33 pm EST

    Tks you :slight_smile:

  • Posted 28 August 2018, 6:31 pm EST

    Hello,

    To meet your requirement, we need to set the MaxWidth of the resizing column to make sure that all the columns are in the width of dataGrid and the horizental scroll will not be shown during the resizing. Also, after dragging any column the width of that column is not * any more, so we need to consider this situation also. We modified the sample accordingly.

    Please refer the same to test whether it meets your need/not.

    Hope it helps.

    Thanks,

    RuchirColumnWidth_C1DataGrid_Fixed.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels