Column Resizing Problem

Posted by: pwickham on 8 September 2017, 2:06 pm EST

  • Posted 8 September 2017, 2:06 pm EST

    I am using a farpoint grid in an application I am working on. I have been ruiing into a problem with the columns in the grid resizing themselves to the default after basically every button click on my screen. The default size is coming up very large I believe 392 This seems to happen when I change or reset the DataSource. So I try to fix it but hard coding it to 160. The bolded code below fixed my issue because it resets the size everytime the column is painted with the GridView ColumnChanged event. The problem is now I am no longer able to resize the column ever. Any idea on this?


    thanks


    // 
    // checkGrid
    // 
    this.layoutRefreshExtender.SetAffectsLayout(this.checkGrid, false);
    this.cslaReadWriteAuthorization.SetApplyAuthorization(this.checkGrid, false);
    this.checkGrid.CategoryHeader = "Name of Check";
    this.checkGrid.CheckDataMember = "";
    this.checkGrid.Columns = new Mercer.RetirementStudio.UI.DataAcquisition.Common.DataServiceGridColumn[0];
    this.checkGrid.ContextMenuString = "";
    this.checkGrid.ContextMenuStrip = this.contextMenuStrip1;
    this.checkGrid.DataSource = null;
    this.checkGrid.DefaultGridBackColor = System.Drawing.Color.White;
    this.checkGrid.DefaultGridFont = new System.Drawing.Font("Microsoft Sans Serif", 8F);
    this.checkGrid.DefaultGridForeColor = System.Drawing.Color.Black;
    this.checkGrid.Dock = System.Windows.Forms.DockStyle.Fill;
    this.checkGrid.DomainEntityConverter = null;
    this.checkGrid.EnabledDataMember = "";
    this.checkGrid.ExpandAll = true;
    this.checkGrid.GridDisabledForeColor = System.Drawing.Color.Gray;
    this.checkGrid.Location = new System.Drawing.Point(0, 0);
    this.checkGrid.Name = "checkGrid";
    this.checkGrid.NameDataMember = "Name";
    this.checkGrid.ShowCheckBoxes = false;
    this.checkGrid.Size = new System.Drawing.Size(827, 241);
    this.checkGrid.TabIndex = 13;
    this.visibilityManager.SetVisibilityProperty(this.checkGrid, null);
    this.checkGrid.CellClicked += new FarPoint.Win.Spread.CellClickEventHandler(this.checkGrid_CellClicked);
    this.checkGrid.ButtonClicked += new FarPoint.Win.Spread.EditorNotifyEventHandler(this.checkGrid_ButtonClicked);
    this.checkGrid.ActiveCellChanged += new FarPoint.Win.Spread.SheetViewPropertyChangeEventHandler(this.checkGrid_ActiveCellChanged);
    this.checkGrid.CheckBoxClicked += new FarPoint.Win.Spread.EditorNotifyEventHandler(this.checkGrid_CheckBoxClicked);
    this.checkGrid.GridView.ColumnChanged += new FarPoint.Win.Spread.SheetViewEventHandler(GridView_ColumnChanged);
              


    private void GridView_ColumnChanged(object sender, FarPoint.Win.Spread.SheetViewEventArgs e)
    {
         this.SetCheckGridFilterWidth();
    }


     private void SetCheckGridFilterWidth()
            {
                if (checkGrid != null && checkGrid.GridView !=null)
                    if (checkGrid.GridView.Columns.Count > 3 && checkGrid.GridView.Columns[3] != null)
                    {
                        this.checkGrid.GridView.Columns[3].Width = 160;
                    }
            }

  • Replied 8 September 2017, 2:06 pm EST

    Hello,

    I am not able to replicate the above described behavior on resetting/changing the DataSource using the Latest build.

    In order to fit the Column Data you may use GetPreferredWidth( ) to re-size the Column instead of setting it to a constant value if the Columns contains data.

    e.g.

    FarPoint.Win.Spread.Column col;
    float size;
    col = fpSpread1.ActiveSheet.Columns[3];
    size = col.GetPreferredWidth();
    col.Width = size;

    The above code will re-size the Column to fit the Data. If this doesn't help please provide us a zipped sample application to debug.

    Thanks,

     

     

     

     

  • Replied 8 September 2017, 2:06 pm EST

    Hello,


    If you set the DataAutoSizeColumns property of the Spread to False, then Spread will not automatically size based on the bound column and will retain your set column width for every column.

Need extra support?

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

Learn More

Forum Channels