Issue with GetCompositeInfo after sorting

Posted by: rfmanuel on 8 September 2017, 2:44 pm EST

  • Posted 8 September 2017, 2:44 pm EST

    I have the following code:

             private void Form1_Load(object sender, EventArgs e)
            {
                this.fpSpread1.ActiveSheet.RowCount = 2;
                this.fpSpread1.ActiveSheet.ColumnCount = 2;

                this.fpSpread1.ActiveSheet.Columns[0].CellType = new FarPoint.Win.Spread.CellType.CheckBoxCellType();

                this.fpSpread1.ActiveSheet.Cells[0, 0].Locked = true;
                if (!this.fpSpread1.ActiveSheet.Models.Style.GetCompositeInfo(0, 0, -1, null).Locked)
                {
                    throw new Exception("Locked failed 1");
                }

                this.fpSpread1.ActiveSheet.Cells[0, 1].Text = "2";

                this.fpSpread1.ActiveSheet.Cells[1, 0].Locked = false;
                if (this.fpSpread1.ActiveSheet.Models.Style.GetCompositeInfo(1, 0, -1, null).Locked)
                {
                    throw new Exception("Unlocked failed 1");
                }

                this.fpSpread1.ActiveSheet.Cells[1, 1].Text = "1";

                FarPoint.Win.Spread.SortInfo[] sortInfo = new FarPoint.Win.Spread.SortInfo[1];
                sortInfo[0] = new FarPoint.Win.Spread.SortInfo(1, true);
                this.fpSpread1.ActiveSheet.SortRows(0, this.fpSpread1.ActiveSheet.RowCount, sortInfo);

                this.fpSpread1.ActiveSheet.Cells[0, 0].Locked = false;
                if (this.fpSpread1.ActiveSheet.Models.Style.GetCompositeInfo(0, 0, -1, null).Locked)
                {
                    throw new Exception("Unlocked failed 2");
                }

                this.fpSpread1.ActiveSheet.Cells[1, 0].Locked = true;
                if (!this.fpSpread1.ActiveSheet.Models.Style.GetCompositeInfo(1, 0, -1, null).Locked)
                {
                    throw new Exception("Locked failed 2");
                }
            }

     The last two exceptions are being thrown.  It appears that right after the sort, the locked properties are not being able to be set correctly.  If I do not do the sort, everything works fine.  Is there some other way to sort that will allow the use of GetCompositeInfo correctly afterwards?

     I've attached the project I'm using for reference.

     Thanks,

    Ryan


    2011/08/TestStyle.zip
  • Replied 8 September 2017, 2:44 pm EST

    Hi Ryan,

    There are two solutions.  You can change the sort to use SortRange instead of SortRows, or you can change the code accessing the style models to translate the view row index to model row index with GetModelRowFromViewRow.

    SortRows is faster since it does not actually move around any data or styles; it just changes the mapping of view row indexes to model row indexes.

    SortRange moves the data and styles around in the models to sort (so it is slower), and does not change the row index mapping.

Need extra support?

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

Learn More

Forum Channels