GetPrefferedWidth

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

  • Posted 8 September 2017, 2:15 pm EST

    Hi guys,

      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.

    Thank you for help.
     
    Vlada 
  • Replied 8 September 2017, 2:15 pm EST

    Hello,


    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.


    Thanks.

  • 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:

    {code}

    using System.Collections.Generic;

    using System.Windows.Forms;

    using FarPoint.Win.Spread.Model;


    namespace WindowsFormsApplication1

    {

        public class DataModel : DefaultSheetDataModel

        {

            private List List;


            public DataModel(List list)

            {

                List = list;

            }


            public override object GetValue(int row, int column)

            {

                if (column < List.Count)

                    return List[column];

                else

                    return null;

            }


        }


        public partial class Form1 : Form

        {

            public Form1()

            {

                InitializeComponent();


                var list = new List() { "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;


                MessageBox.Show(fpSpread1_Sheet1.Columns[0].GetPreferredWidth().ToString());

            }



            //designer


            ///

            /// Required designer variable.

            ///

            private System.ComponentModel.IContainer components = null;


            ///

            /// Clean up any resources being used.

            ///

            /// true if managed resources should be disposed; otherwise, false.

            protected override void Dispose(bool disposing)

            {

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

                {

                    components.Dispose();

                }

                base.Dispose(disposing);

            }


            #region Windows Form Designer generated code


            ///

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

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

            ///

            private void InitializeComponent()

            {

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

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

                ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).BeginInit();

                ((System.ComponentModel.ISupportInitialize)(this.fpSpread1_Sheet1)).BeginInit();

                this.SuspendLayout();

                // 

                // 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_Sheet1});

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

                this.fpSpread1.TabIndex = 0;

                // 

                // fpSpread1_Sheet1

                // 

                this.fpSpread1_Sheet1.Reset();

                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.Controls.Add(this.fpSpread1);

                this.Name = "Form1";

                this.Text = "Form1";

                ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).EndInit();

                ((System.ComponentModel.ISupportInitialize)(this.fpSpread1_Sheet1)).EndInit();

                this.ResumeLayout(false);


            }


            #endregion


            private FarPoint.Win.Spread.FpSpread fpSpread1;

            private FarPoint.Win.Spread.SheetView fpSpread1_Sheet1;


        }

    }

     

    {code} 

  • Replied 8 September 2017, 2:15 pm EST

    Vlada,

    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