[C1DataGrid] resizing columns while scrolling - issue

Posted by: jakub.cieslinski on 9 January 2020, 1:18 am EST

    • Post Options:
    • Link

    Posted 9 January 2020, 1:18 am EST - Updated 3 October 2022, 11:59 pm EST

    Hello,

    i got issue with C1DataGrid, while i’m scrolling horizontally, colums resize randomly. At the attachment Purple column (Czas (Zmienna_5)) resized, when i expect that column witdh should be almost the same - fit to header - like in Blue column (Wartosc (Zmienna_4)). Each scroll sliding changes random column width. Any ideas?

  • Posted 9 January 2020, 4:48 pm EST

    Hello,

    With the 2017v1 version, there was one similar issue (bug) that occurred when scrolling DataGrid with column’s Width set to Auto. However, the issue was fixed and no build later than *.20171.550 should show the issue. Therefore, what is the ComponentOne build version that you are using?

    If you’re using a build later than *.2017v1 and still facing the issue, can you please share the code snippet related to C1DataGrid?

    Thanks & regards,

    Ruchir

  • Posted 9 January 2020, 11:39 pm EST

    Thank’s for quick reply. We’re using 20173.578, below i’m sharing code:

    
     private static void SetColumnsAndRows(DependencyObject source, ObservableCollection<ChartTableValue> columnsList, DependencyPropertyChangedEventArgs e)
            {
                var dataGrid = source as C1DataGrid;
                if (dataGrid == null || columnsList == null || columnsList.Count <= 0) return;
    
     dataGrid.Columns.Clear();
                foreach (var label in _labels)
                {
                    dataGrid.Columns.Add(new DataGridTextColumn()
                    {
                        Width =  DataGridLength.Auto,
                        Header = label,
                        Binding = new Binding(label.Replace(' ', '_')),
                        CanUserSort = false,
                        CanUserResizeRows = false,
                        CanUserMove = false,
                        CanUserResize = true,
                        CanUserGroup = false,
                        IsSelectable = false
                    });
                }
    
                dataGrid.ColumnWidth = DataGridLength.Auto;
                dataGrid.GridLinesVisibility = DataGridGridLinesVisibility.All;
                dataGrid.MouseLeftButtonDown += DataGridOnMouseLeftButtonDown;
    
                dataGrid.LoadedColumnHeaderPresenter += (s, f) =>
                {
                    var colorBrush = IntToColor(_colors[f.Column.Index]);
                    f.Column.Width = new DataGridLength(1, DataGridUnitType.Auto);
                    f.Column.HeaderPresenter.HorizontalContentAlignment = HorizontalAlignment.Center;
                    f.Column.HeaderPresenter.Background = colorBrush;
                    f.Column.HeaderPresenter.Foreground = BackgroundToForegroundColor(colorBrush);
                };
    ...
    }
    
    

    All has been written as behavior.

    Thanks,

    Jacob

  • Posted 12 January 2020, 5:19 pm EST

    Hi Jacob,

    Thank you for sharing the code snippet related to rendering C1DataGrid’s column headers, however it was not sufficient to replicate the problem.

    I prepared an application using the code (and adding some extra code for generating the rows) however I did not observe the problem using C1 version: *.20173.578.

    Can you please run attached application at your end and see if the issue occurs? If it does not, could you please modify it and share back so that we can observe the problem and assist accordingly?

    Thanks & regards,

    Ruchir

    ColResize_C1DataGrid.zip

  • Posted 13 January 2020, 10:37 am EST

    Hello again,

    Thank you for your example, but there my problem does’t occurs. In your application columns resize correctly, when i was stretching columns, each scroll slide fit columns like as expect.

    Anyway i solved my problem and below i am sharing code

      
    dataGrid.LoadedCellPresenter += (s, f) =>
                {
                    f.Cell.Column.Width = new DataGridLength(1, DataGridUnitType.Star);
                    f.Cell.Column.Width = new DataGridLength(1, DataGridUnitType.AutoStar);
                    f.Cell.Presenter.Foreground = _foreground;
                    f.Cell.Presenter.Background = _background;
                    f.Cell.Presenter.HorizontalContentAlignment = HorizontalAlignment.Center;
                };
    
    

    Thank you for your help and time.

    Thanks,

    Jacob

Need extra support?

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

Learn More

Forum Channels