columnwidth does not resizing to bestfit in width

3 posts, 1 answers
  1. Andre
    Andre avatar
    41 posts
    Member since:
    Feb 2018

    Posted 16 Apr 2018 Link to this post

    hi

    why does the column width not fit automatically when adding or deleting a row ?

    when loading, it works.

     

     

           private void DgvTaskRunningLoad() {
                using (this.dgvTaskRunning.DeferRefresh()) {
                    dgvTaskRunning.DataSource = Sql.Dashboard_listTaskRunning();

                    // layout
                    dgvTaskRunning.ShowGroupPanel = false;
                    dgvTaskRunning.ReadOnly = true;
                    dgvTaskRunning.ShowRowHeaderColumn = false;
                    dgvTaskRunning.AutoScroll = true;
                    dgvTaskRunning.MasterTemplate.AutoGenerateColumns = true;
                    dgvTaskRunning.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None;
                    dgvTaskRunning.BestFitColumns(BestFitColumnMode.AllCells);

                    // grid
                    dgvTaskRunning.Padding = new Padding(10);

                    // cell
                    dgvTaskRunning.TableElement.CellSpacing = 3;

                    // column
                    foreach (var col in dgvTaskRunning.Columns) {
                        col.IsVisible = false;
                    }

                    dgvTaskRunning.Columns[ColumnTitle.GridTasklistMail.subject].HeaderText = @"Task";
                    dgvTaskRunning.Columns[ColumnTitle.GridOverviewTimestamp.dashboardUser].HeaderText = $@"User";
                    dgvTaskRunning.Columns[ColumnTitle.GridTasklistMail.reference].HeaderText = $@"Reference";
                    dgvTaskRunning.Columns[ColumnTitle.GridCostAccount.costAccount].HeaderText = $@"CostAccount";
                    dgvTaskRunning.Columns[ColumnTitle.GridTaskTimestamp.timestampStart].HeaderText = $@"Start";
                    dgvTaskRunning.Columns[ColumnTitle.GridOverviewTimestamp.hoursWorked].HeaderText = $@"hours worked";
                    dgvTaskRunning.Columns[ColumnTitle.GridTasklistMail.description].HeaderText = $@"Description";

                    dgvTaskRunning.Columns[ColumnTitle.GridTasklistMail.reference].TextAlignment = ContentAlignment.MiddleCenter;
                    dgvTaskRunning.Columns[ColumnTitle.GridCostAccount.costAccount].TextAlignment = ContentAlignment.MiddleCenter;
                    dgvTaskRunning.Columns[ColumnTitle.GridOverviewTimestamp.hoursWorked].TextAlignment = ContentAlignment.MiddleCenter;

                    // visibility
                    dgvTaskRunning.Columns[ColumnTitle.GridTasklistMail.subject].IsVisible = true;
                    dgvTaskRunning.Columns[ColumnTitle.GridOverviewTimestamp.dashboardUser].IsVisible = true;
                    dgvTaskRunning.Columns[ColumnTitle.GridTasklistMail.reference].IsVisible = true;
                    dgvTaskRunning.Columns[ColumnTitle.GridCostAccount.costAccount].IsVisible = true;
                    dgvTaskRunning.Columns[ColumnTitle.GridTaskTimestamp.timestampStart].IsVisible = true;
                    dgvTaskRunning.Columns[ColumnTitle.GridOverviewTimestamp.hoursWorked].IsVisible = true;
                    dgvTaskRunning.Columns[ColumnTitle.GridTasklistMail.description].IsVisible = true;

                    // filtering
                    dgvTaskRunning.EnableFiltering = true;
                    dgvTaskRunning.ShowFilteringRow = false;
                    dgvTaskRunning.ShowHeaderCellButtons = true;
                }
            }

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2684 posts

    Posted 17 Apr 2018 Link to this post

    Hello Andre,

    Thank you for writing.

    By default, the BestFitColumns method is not automatically executed after any changes are made to the grid. You need to manually call the BestFitColumns method if you want to fit the columns again. 

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Andre
    Andre avatar
    41 posts
    Member since:
    Feb 2018

    Posted 17 Apr 2018 in reply to Dimitar Link to this post

    hi dimitar

    best thanks for the hint. bestfitcolumns only is not enough yet in my case but with the other parameters it works.
    thank you !

Back to Top