Selection count is zero if selection is in last column or row of sheet

Posted by: agib1977 on 8 September 2017, 12:38 pm EST

  • Posted 8 September 2017, 12:38 pm EST

    Hi,


    I have just upgraded to version 3 (3.0.2003.2005) from version 2, in which this used to work. I have tried on both .NET v1 and v2 and get the same problem.


    I have code that responds to the EnterCell event of the sheet. In this event it makes use of the current selection (uses GetSelection(0)). On most cells this works. However, if the cell is in the last row or column of the grid then the selection count is 0. Adding a selection through code does not work either.


    Code for an example custom control ctlSheetViewer is given below. If the control is placed on a form then the problem will occur.


    I would be grateful for any help that can be provided.


    Thanks,


    Alec.

    using FarPoint.Win.Spread.Model;

    namespace WindowsApplication1
    {
    internal class ctlSheetViewer : System.Windows.Forms.UserControl
    {
    private FarPoint.Win.Spread.FpSpread ctlGrid;

    private FarPoint.Win.Spread.SheetView ctlGrid_Sheet1;

    ///
    /// Required designer variable.
    ///

    private System.ComponentModel.Container components = null;

    public ctlSheetViewer()
    {
    // This call is required by the Windows.Forms Form Designer.
    InitializeComponent();
    }

    ///
    /// Clean up any resources being used.
    ///

    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    //TODO: Unregister from any events.

    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }

    #region Component Designer generated code
    ///
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///

    private void InitializeComponent()
    {
    this.ctlGrid = new FarPoint.Win.Spread.FpSpread();
    this.ctlGrid_Sheet1 = new FarPoint.Win.Spread.SheetView();
    ((System.ComponentModel.ISupportInitialize)(this.ctlGrid)).BeginInit();
    ((System.ComponentModel.ISupportInitialize)(this.ctlGrid_Sheet1)).BeginInit();
    this.SuspendLayout();
    //
    // ctlGrid
    //

    this.ctlGrid.AccessibleDescription = "";
    this.ctlGrid.Dock = System.Windows.Forms.DockStyle.Fill;
    this.ctlGrid.EditModeReplace = true;
    this.ctlGrid.Location = new System.Drawing.Point(0, 0);
    this.ctlGrid.Name = "ctlGrid";
    this.ctlGrid.ScrollBarShowMax = false;
    this.ctlGrid.Sheets.AddRange(new FarPoint.Win.Spread.SheetView[] {
    this.ctlGrid_Sheet1});
    this.ctlGrid.Size = new System.Drawing.Size(480, 352);
    this.ctlGrid.TabIndex = 0;
    this.ctlGrid.EnterCell += new FarPoint.Win.Spread.EnterCellEventHandler(this.ctlGrid_EnterCell);
    this.ctlGrid.SetViewportPreferredHeight(0, 499);
    //
    // ctlGrid_Sheet1
    //

    this.ctlGrid_Sheet1.Reset();
    // Formulas and custom names must be loaded with R1C1 reference style
    this.ctlGrid_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1;
    this.ctlGrid_Sheet1.ColumnCount = 10;
    this.ctlGrid_Sheet1.RowCount = 10;
    this.ctlGrid_Sheet1.AutoUpdateNotes = true;
    this.ctlGrid_Sheet1.Columns.Default.Width = 64F;
    this.ctlGrid_Sheet1.RowHeader.Columns.Default.Resizable = false;
    this.ctlGrid_Sheet1.Rows.Default.Height = 17F;
    this.ctlGrid_Sheet1.SelectionPolicy = FarPoint.Win.Spread.Model.SelectionPolicy.MultiRange;
    this.ctlGrid_Sheet1.SheetName = "Sheet1";
    this.ctlGrid_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1;
    //
    // ctlSheetViewer
    //

    this.Controls.Add(this.ctlGrid);
    this.Name = "ctlSheetViewer";
    this.Size = new System.Drawing.Size(480, 352);
    ((System.ComponentModel.ISupportInitialize)(this.ctlGrid)).EndInit();
    ((System.ComponentModel.ISupportInitialize)(this.ctlGrid_Sheet1)).EndInit();
    this.ResumeLayout(false);

    }
    #endregion

    private void
    ctlGrid_EnterCell(object sender, FarPoint.Win.Spread.EnterCellEventArgs e)
    {

    CellRange cr = ctlGrid_Sheet1.GetSelection(0);

    if (cr == null)
    {
    ctlGrid_Sheet1.AddSelection(e.Row, e.Column, 1, 1);
    cr = ctlGrid_Sheet1.GetSelection(0);
    }

    int i = ctlGrid_Sheet1.SelectionCount;

    if (cr.Row == -1)
    {
    if (cr.Column == -1)
    {

    }
    else
    {

    }
    }
    else if (cr.Column == -1)
    {

    }
    else
    {

    }

    }

    }
    }

     
  • Replied 8 September 2017, 12:38 pm EST

    OK. Thanks.
  • Replied 8 September 2017, 12:38 pm EST

    I have just experienced a similar problem in the newest 2.5 version (11). When trying to call GetSelection(0) on the sheet (when selecting all of the cells), it returns null instead of the cell range that it used to return in the previous version (9). It sounds like this might be the same problem that was identified in the 3.0 tree. Can you look into this and see if we can get another maintenance release for 2.5?

    Thanks,
    Brian
  • Replied 8 September 2017, 12:38 pm EST

    Brian -

    The bug has been reported in 2.5 but I do not have a time frame for when the next maintenance release is scheduled.  You should be able to work around it by using the SelectionModel directly...

    FarPoint.Win.Spread.Model.CellRange cr = fpSpread1.Sheets[0].Models.Selection[0];

  • Replied 8 September 2017, 12:38 pm EST

    The same bug also seems to be in version 3.0.2003.2005.
    Has it been fixed in 3.0.2004.2005?

    Thomas
  • Replied 8 September 2017, 12:38 pm EST

    Alec -

    I was able to reproduce this and will write it up as a bug for the development team to fix.
  • Replied 8 September 2017, 12:38 pm EST

    Thomas -

    It does appear to be fixed in 3.0.2004
Need extra support?

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

Learn More

Forum Channels