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:


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Goat.DataClasses;


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


            public override int ColumnCount { get { return 11; } }
            public override int RowCount { get { return 24; } }


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


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


            public override void SetValue(int row, int column, object value)
            {
                if (_dataSource == null) return;
                if (_dataSource.HourlyOffers[row + 1].Limits == null) return;


                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;


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


                base.SetValue(row, column, value);
            }


            public override bool IsEditable(int row, int column)
            {
                return (column < 5 || column > 6);
            }


            public override bool IsEmpty()
            {
                return _dataSource == null;
            }


            public override bool IsRowUsed(int row)
            {
                return (row < 24);
            }
        }
    }


     


    I set it by using


    fpSpread1.Sheets[0].Models.Data = new FarPoint.Win.Spread.Model.HourlyLimitsDataModel();

  • 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