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

    <P>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.</P>
    <P> I am currently using Version 4.0.3512.2008</P>
  • Replied 8 September 2017, 2:29 pm EST

    <p>Hello,</p><p>Can you send us a sample showing how are you creating a custom data model?<br></p><p>Thanks. <br></p>
  • Replied 8 September 2017, 2:29 pm EST

    <P>Custom Data Model Code:</P>
    <P><FONT face="courier new,courier">using System;<BR>using System.Collections.Generic;<BR>using System.Linq;<BR>using System.Text;<BR>using Goat.DataClasses;</FONT></P>
    <P><FONT face="courier new,courier">namespace FarPoint.Win.Spread.Model<BR>{<BR>    public class HourlyLimitsDataModel : BaseSheetDataModel<BR>    {<BR>        private Offer _dataSource;<BR>        public Offer DataSource { get { return _dataSource; } set { _dataSource = value; FireChanged(0, 0, this.RowCount, this.ColumnCount, SheetDataModelEventType.ModelUpdated); } }</FONT></P>
    <P><FONT face="courier new,courier">        public override int ColumnCount { get { return 11; } }<BR>        public override int RowCount { get { return 24; } }</FONT></P>
    <P><FONT face="courier new,courier">        public override object GetValue(int row, int column)<BR>        {<BR>            if (_dataSource == null) return null;<BR>            switch (column)<BR>            {<BR>                case 0:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.EmergencyMin;<BR>                case 1:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.EconomicMin;<BR>                case 2:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.RegulationMin;<BR>                case 3:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.RegulationMax;<BR>                case 4:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.EconomicMax;<BR>                case 5:<BR>                    return _dataSource.MustOffer;<BR>                case 6:<BR>                    return double.IsNaN(_dataSource.HourlyOffers[row + 1].CrowDerate) ? null : (object)_dataSource.HourlyOffers[row+1].CrowDerate;<BR>                case 7:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.EmergencyMax;<BR>                case 8:<BR>                    return _dataSource.HourlyOffers[row + 1].EnergyOffer.CommitStatus;<BR>                case 9:<BR>                    return _dataSource.HourlyOffers[row + 1].EnergyOffer.DispatchStatus;<BR>                case 10:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.Notes;<BR>            }<BR>            return base.GetValue(row, column);<BR>        }</FONT></P>
    <P><FONT face="courier new,courier">        public override string GetNote(int row, int column)<BR>        {<BR>            if (_dataSource == null) return null;<BR>            switch (column)<BR>            {<BR>                case 0:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.IsEmergencyMinValid ? null : "Invalid";<BR>                case 1:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.IsEconomicMinValid ? null : "Invalid";<BR>                case 2:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.IsRegulationMinValid ? null : "Invalid";<BR>                case 3:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.IsRegulationMaxValid ? null : "Invalid";<BR>                case 4:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.IsEconomicMaxValid ? null : "Invalid";<BR>                case 5:<BR>                    return null;<BR>                case 6:<BR>                    return null;<BR>                case 7:<BR>                    return _dataSource.HourlyOffers[row + 1].Limits.IsEmergencyMaxValid ? null : "Invalid";<BR>                case 8:<BR>                    return null;<BR>                case 9:<BR>                    return null;<BR>                case 10:<BR>                    return null;<BR>            }<BR>            return base.GetNote(row, column);<BR>        }</FONT></P>
    <P><FONT face="courier new,courier">        public override void SetValue(int row, int column, object value)<BR>        {<BR>            if (_dataSource == null) return;<BR>            if (_dataSource.HourlyOffers[row + 1].Limits == null) return;</FONT></P>
    <P><FONT face="courier new,courier">            if (column <= 7)<BR>            {<BR>                double newValue;<BR>                if (value == null) newValue = double.NaN;<BR>                if (!Double.TryParse(value.ToString(), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out newValue))<BR>                    return;</FONT></P>
    <P><FONT face="courier new,courier">                switch (column)<BR>                {<BR>                    case 0:<BR>                        DataSource.HourlyOffers[row + 1].Limits.EmergencyMin = newValue;<BR>                        return;<BR>                    case 1:<BR>                        DataSource.HourlyOffers[row + 1].Limits.EconomicMin = newValue;<BR>                        return;<BR>                    case 2:<BR>                        DataSource.HourlyOffers[row + 1].Limits.RegulationMin = newValue;<BR>                        return;<BR>                    case 3:<BR>                        DataSource.HourlyOffers[row + 1].Limits.RegulationMax = newValue;<BR>                        return;<BR>                    case 4:<BR>                        DataSource.HourlyOffers[row + 1].Limits.EconomicMax = newValue;<BR>                        return;<BR>                    case 7:<BR>                        DataSource.HourlyOffers[row + 1].Limits.EmergencyMax = newValue;<BR>                        return;<BR>                }<BR>            }<BR>            else if (column <= 9)<BR>            {<BR>                switch (column)<BR>                {<BR>                    case 8:<BR>                        DataSource.HourlyOffers[row + 1].EnergyOffer.CommitStatus = (value == null) ? null : Status.Parse(value.ToString());<BR>                        return;<BR>                    case 9:<BR>                        DataSource.HourlyOffers[row + 1].EnergyOffer.DispatchStatus = (value == null) ? null : Status.Parse(value.ToString());<BR>                        return;<BR>                }<BR>            }<BR>            else if (column == 10)<BR>            {<BR>                DataSource.HourlyOffers[row + 1].Limits.Notes = Convert.ToString(value);<BR>            }</FONT></P>
    <P><FONT face="courier new,courier">            base.SetValue(row, column, value);<BR>        }</FONT></P>
    <P><FONT face="courier new,courier">        public override bool IsEditable(int row, int column)<BR>        {<BR>            return (column < 5 || column > 6);<BR>        }</FONT></P>
    <P><FONT face="courier new,courier">        public override bool IsEmpty()<BR>        {<BR>            return _dataSource == null;<BR>        }</FONT></P>
    <P><FONT face="courier new,courier">        public override bool IsRowUsed(int row)<BR>        {<BR>            return (row < 24);<BR>        }<BR>    }<BR>}</FONT></P>
    <P><FONT face="Courier New"></FONT> </P>
    <P><FONT face="Courier New">I set it by using <FONT size=1></P>
    <P>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>();</P></FONT></FONT>
  • Replied 8 September 2017, 2:29 pm EST

    <p>Hello,</p><p>Can you send me the running sample for the same because in the code you have provided Offer class is missing.</p><p>Thanks. <br></p>
  • Replied 8 September 2017, 2:29 pm EST

    <p>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?</p><p>Thanks,</p><p>Jim <br></p>
  • Replied 8 September 2017, 2:29 pm EST

    <p>Hello Jim,</p><p>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.</p><p>Thanks. <br></p>
Need extra support?

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

Learn More

Forum Channels