Posted by: vkubalek on 8 September 2017, 2:15 pm EST

  • Posted 8 September 2017, 2:15 pm EST

    <div>Hi guys,</div><div>
    </div><div>  We use FarPoint.Win.Spread (dll ver 4.0.2010.2005) and we have a problem with method GetPrefferedWidth (Column class). We use our own data model (based on DefaultSheetDataModel) and style model (based on DefaultSheetStyleModel). Question is What do we have to implement the method GetPrefferedWidth work? Now it return only the width of the header, which is not in our model.</div><div>
    </div><div>Thank you for help.</div><div> </div><div>Vlada </div>
  • Replied 8 September 2017, 2:15 pm EST


    We are unable to replicate the issue with the latest build of Spread as it is taking the maximum width of the cells in that column and not the column headers width. Please try it again with the latest build 4.0.2015.2005 of Spread, else please send us a sample replicating the issue for us to debug and investigate more on this issue.


  • Replied 8 September 2017, 2:15 pm EST

    Hello, now we are refactoring this part and our problem is actual again. GetPreferredWidth doesn't work with our datamodel.

    Here is example:


    using System.Collections.Generic;

    using System.Windows.Forms;

    using FarPoint.Win.Spread.Model;

    namespace WindowsFormsApplication1


        public class DataModel : DefaultSheetDataModel


            private List<string> List;

            public DataModel(List<string> list)


                List = list;


            public override object GetValue(int row, int column)


                if (column < List.Count)

                    return List[column];


                    return null;



        public partial class Form1 : Form


            public Form1()



                var list = new List<string>() { "safgdsg fgdg", "sagdsfg dsfgsdg", "adg sdfg sdfg sdfg" };

                var dataModel = new DataModel(list);

                fpSpread1_Sheet1.Models.Data = dataModel;

                fpSpread1_Sheet1.ColumnCount = 5;

                fpSpread1_Sheet1.RowCount = 5;




            /// <summary>

            /// Required designer variable.

            /// </summary>

            private System.ComponentModel.IContainer components = null;

            /// <summary>

            /// Clean up any resources being used.

            /// </summary>

            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

            protected override void Dispose(bool disposing)


                if (disposing && (components != null))






            #region Windows Form Designer generated code

            /// <summary>

            /// Required method for Designer support - do not modify

            /// the contents of this method with the code editor.

            /// </summary>

            private void InitializeComponent()


                this.fpSpread1 = new FarPoint.Win.Spread.FpSpread();

                this.fpSpread1_Sheet1 = new FarPoint.Win.Spread.SheetView();





                // fpSpread1


                this.fpSpread1.AccessibleDescription = "";

                this.fpSpread1.Dock = System.Windows.Forms.DockStyle.Fill;

                this.fpSpread1.Location = new System.Drawing.Point(0, 0);

                this.fpSpread1.Name = "fpSpread1";

                this.fpSpread1.Sheets.AddRange(new FarPoint.Win.Spread.SheetView[] {


                this.fpSpread1.Size = new System.Drawing.Size(292, 273);

                this.fpSpread1.TabIndex = 0;


                // fpSpread1_Sheet1



                this.fpSpread1_Sheet1.SheetName = "Sheet1";


                // Form1


                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

                this.ClientSize = new System.Drawing.Size(292, 273);


                this.Name = "Form1";

                this.Text = "Form1";






            private FarPoint.Win.Spread.FpSpread fpSpread1;

            private FarPoint.Win.Spread.SheetView fpSpread1_Sheet1;





  • Replied 8 September 2017, 2:15 pm EST


    Your DataModel class derives from the DefaultSheetDataModel class which implements INonEmptyCells and IOptimizedEnumerationSupport2 interfaces. The INonEmptyCells interface has NonEmptyRowCount and NonEmptyColumnCount for determining the area of the sheet which contain non-empty cells. The IOptimizedEnumerationSupport2 interface has methods for enumerating the non-empty cells. The GetPreferredColumnWidth method uses these properties and methods to improve performance (i.e. skip areas of the sheet that are completely empty). The DefaultSheetDataModel's implementation of these properties and methods is based on the DefaultSheetDataModel's storage of cell values. In your example, you are not putting any cell values into the DefaultSheetDataModel's storage (i.e. you are overriding the DefaultSheetDataModel's storage). Thus, the GetPreferredColumnWidth method thinks that the sheet is empty and only uses the header area in its calculations. If you are going to derive from the DefaultSheetDataModel class and override the storage of cell values (i.e. override GetValue) then you will also want to override the properties and methods for finding non-empty cells (i.e. NonEmptyRowCount, NonEmptyColumnCount, NextNonEmptyRow, NextNonEmptyColumnInRow).

Need extra support?

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

Learn More

Forum Channels