Column Header Text and Spans reset when changing Sheet Data Model

Posted by: jimvoss on 8 September 2017, 2:29 pm EST

  • Posted 8 September 2017, 2:29 pm EST

    I am using a custom data model to facilitate displaying a class to the user to edit. However, when I set the data model of the SheetView, all of the column headers I had defined are reset to use A, B, C, etc and the column header spans are removed.


     I am currently using Version 4.0.3512.2008

  • Replied 8 September 2017, 2:29 pm EST

    Hello,

    Can you send us a sample showing how are you creating a custom data model?

    Thanks.

  • Replied 8 September 2017, 2:29 pm EST

    Custom Data Model Code:


    <FONT face="courier new,courier">using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Goat.DataClasses;</FONT>


    <FONT face="courier new,courier">namespace FarPoint.Win.Spread.Model
    {
        public class HourlyLimitsDataModel : BaseSheetDataModel
        {
            private Offer _dataSource;
            public Offer DataSource { get { return _dataSource; } set { _dataSource = value; FireChanged(0, 0, this.RowCount, this.ColumnCount, SheetDataModelEventType.ModelUpdated); } }</FONT>


    <FONT face="courier new,courier">        public override int ColumnCount { get { return 11; } }
            public override int RowCount { get { return 24; } }</FONT>


    <FONT face="courier new,courier">        public override object GetValue(int row, int column)
            {
                if (_dataSource == null) return null;
                switch (column)
                {
                    case 0:
                        return _dataSource.HourlyOffers[row + 1].Limits.EmergencyMin;
                    case 1:
                        return _dataSource.HourlyOffers[row + 1].Limits.EconomicMin;
                    case 2:
                        return _dataSource.HourlyOffers[row + 1].Limits.RegulationMin;
                    case 3:
                        return _dataSource.HourlyOffers[row + 1].Limits.RegulationMax;
                    case 4:
                        return _dataSource.HourlyOffers[row + 1].Limits.EconomicMax;
                    case 5:
                        return _dataSource.MustOffer;
                    case 6:
                        return double.IsNaN(_dataSource.HourlyOffers[row + 1].CrowDerate) ? null : (object)_dataSource.HourlyOffers[row+1].CrowDerate;
                    case 7:
                        return _dataSource.HourlyOffers[row + 1].Limits.EmergencyMax;
                    case 8:
                        return _dataSource.HourlyOffers[row + 1].EnergyOffer.CommitStatus;
                    case 9:
                        return _dataSource.HourlyOffers[row + 1].EnergyOffer.DispatchStatus;
                    case 10:
                        return _dataSource.HourlyOffers[row + 1].Limits.Notes;
                }
                return base.GetValue(row, column);
            }</FONT>


    <FONT face="courier new,courier">        public override string GetNote(int row, int column)
            {
                if (_dataSource == null) return null;
                switch (column)
                {
                    case 0:
                        return _dataSource.HourlyOffers[row + 1].Limits.IsEmergencyMinValid ? null : "Invalid";
                    case 1:
                        return _dataSource.HourlyOffers[row + 1].Limits.IsEconomicMinValid ? null : "Invalid";
                    case 2:
                        return _dataSource.HourlyOffers[row + 1].Limits.IsRegulationMinValid ? null : "Invalid";
                    case 3:
                        return _dataSource.HourlyOffers[row + 1].Limits.IsRegulationMaxValid ? null : "Invalid";
                    case 4:
                        return _dataSource.HourlyOffers[row + 1].Limits.IsEconomicMaxValid ? null : "Invalid";
                    case 5:
                        return null;
                    case 6:
                        return null;
                    case 7:
                        return _dataSource.HourlyOffers[row + 1].Limits.IsEmergencyMaxValid ? null : "Invalid";
                    case 8:
                        return null;
                    case 9:
                        return null;
                    case 10:
                        return null;
                }
                return base.GetNote(row, column);
            }</FONT>


    <FONT face="courier new,courier">        public override void SetValue(int row, int column, object value)
            {
                if (_dataSource == null) return;
                if (_dataSource.HourlyOffers[row + 1].Limits == null) return;</FONT>


    <FONT face="courier new,courier">            if (column <= 7)
                {
                    double newValue;
                    if (value == null) newValue = double.NaN;
                    if (!Double.TryParse(value.ToString(), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out newValue))
                        return;</FONT>


    <FONT face="courier new,courier">                switch (column)
                    {
                        case 0:
                            DataSource.HourlyOffers[row + 1].Limits.EmergencyMin = newValue;
                            return;
                        case 1:
                            DataSource.HourlyOffers[row + 1].Limits.EconomicMin = newValue;
                            return;
                        case 2:
                            DataSource.HourlyOffers[row + 1].Limits.RegulationMin = newValue;
                            return;
                        case 3:
                            DataSource.HourlyOffers[row + 1].Limits.RegulationMax = newValue;
                            return;
                        case 4:
                            DataSource.HourlyOffers[row + 1].Limits.EconomicMax = newValue;
                            return;
                        case 7:
                            DataSource.HourlyOffers[row + 1].Limits.EmergencyMax = newValue;
                            return;
                    }
                }
                else if (column <= 9)
                {
                    switch (column)
                    {
                        case 8:
                            DataSource.HourlyOffers[row + 1].EnergyOffer.CommitStatus = (value == null) ? null : Status.Parse(value.ToString());
                            return;
                        case 9:
                            DataSource.HourlyOffers[row + 1].EnergyOffer.DispatchStatus = (value == null) ? null : Status.Parse(value.ToString());
                            return;
                    }
                }
                else if (column == 10)
                {
                    DataSource.HourlyOffers[row + 1].Limits.Notes = Convert.ToString(value);
                }</FONT>


    <FONT face="courier new,courier">            base.SetValue(row, column, value);
            }</FONT>


    <FONT face="courier new,courier">        public override bool IsEditable(int row, int column)
            {
                return (column < 5 || column > 6);
            }</FONT>


    <FONT face="courier new,courier">        public override bool IsEmpty()
            {
                return _dataSource == null;
            }</FONT>


    <FONT face="courier new,courier">        public override bool IsRowUsed(int row)
            {
                return (row < 24);
            }
        }
    }</FONT>


    <FONT face="Courier New"></FONT> 


    <FONT face="Courier New">I set it by using <FONT size=1>


    fpSpread1</FONT><FONT color=#408080 size=1><FONT color=#408080 size=1>.</FONT></FONT><FONT size=1>Sheets[0]</FONT><FONT color=#408080 size=1><FONT color=#408080 size=1>.</FONT></FONT><FONT size=1>Models</FONT><FONT color=#408080 size=1><FONT color=#408080 size=1>.</FONT></FONT><FONT size=1>Data </FONT><FONT color=#408080 size=1><FONT color=#408080 size=1>=</FONT></FONT><FONT size=1> </FONT><FONT color=#0000ff size=1><FONT color=#0000ff size=1>new</FONT></FONT><FONT size=1> FarPoint</FONT><FONT color=#408080 size=1><FONT color=#408080 size=1>.</FONT></FONT><FONT size=1>Win</FONT><FONT color=#408080 size=1><FONT color=#408080 size=1>.</FONT></FONT><FONT size=1>Spread</FONT><FONT color=#408080 size=1><FONT color=#408080 size=1>.</FONT></FONT><FONT size=1>Model</FONT><FONT color=#408080 size=1><FONT color=#408080 size=1>.</FONT></FONT><B><FONT color=#2b91af size=1><FONT color=#2b91af size=1>HourlyLimitsDataModel</B></FONT></FONT><FONT size=1>();

    </FONT></FONT>
  • Replied 8 September 2017, 2:29 pm EST

    Hello,

    Can you send me the running sample for the same because in the code you have provided Offer class is missing.

    Thanks.

  • Replied 8 September 2017, 2:29 pm EST

    I discovered my problem: When the class was originally instantiated, it had a NULL datasource, which caused the columncount and rowcount to be 0. This seemed to remove all of the styles. Is that by design or is this a bug of fpspread?

    Thanks,

    Jim

  • Replied 8 September 2017, 2:29 pm EST

    Hello Jim,

    It is the intended behavior and you need to set Rows and Columns count after instantiating the class and then set the styling accordingly thereafter.

    Thanks.

Need extra support?

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

Learn More

Forum Channels