CellClick fires when dragging column

Posted by: lewis-fp on 8 September 2017, 1:54 pm EST

  • Posted 8 September 2017, 1:54 pm EST

    Hi,

    I am having a problem with grid sorting and column moving.  I manually sort the grid data via the cellclick event, e.g. in CellClick I check if e.ColumnHeader is true and if so I call my manual sorting method which sorts data, changes the header sort icon etc..

    I have also enabled column dragging, my problem is that when the mouse is pressed (left button down) on a columnheader but not released the cellclick fires.  So in attempting to drag a column if fires cellclick which then sorts.  I want users to be able to move a column without sorting it.  I tried using mousedown and mouseup events to check for clicking in a column header, e.g. using code like that below:

            private void grid_MouseDown(object sender, MouseEventArgs e)
            {
                FpSpread grid = (FpSpread) sender;
                int rvi = grid.GetActiveRowViewportIndex();
                int cvi = grid.GetActiveColumnViewportIndex();
                _cellRangeMouseDown = grid.GetCellFromPixel(rvi, cvi, e.X, e.Y);
                if (_cellRangeMouseDown.Row != - 1)    // We are only interested when header selected
                {
                    _cellRangeMouseDown = null;
                }
            }

            private void grid_MouseUp(object sender, MouseEventArgs e)
            {
                if (_cellRangeMouseDown != null)
                {
                    FpSpread grid = (FpSpread) sender;
                    int rvi = grid.GetActiveRowViewportIndex();
                    int cvi = grid.GetActiveColumnViewportIndex();
                    CellRange cellRangeMouseDown = grid.GetCellFromPixel(rvi, cvi, e.X, e.Y);
                    if (cellRangeMouseDown.Column == _cellRangeMouseDown.Column)
                    {
                        // User has clicked a column header so sort by that column
                        SortGrid(grid, cellRangeMouseDown.Column);
                    }
                }
            }

     but when a column is clicked GetCellFromPixel just returns -1,-1,-1,-1

     How can I separate the column dragging and the column sorting whilst still being able to use my own custom sort method as opposed to having auto-sorting?

     Regards,

    Lewis

  • Replied 8 September 2017, 1:54 pm EST

    Use the HitTest method to determine where in the Spread you are located.
  • Replied 8 September 2017, 1:54 pm EST

    Thanks for your reply.  Are you able to provide any more details on the HitTest method please?

    I've searched via the Object Browser and it is not coming up with a HitTest method in any FarPoint libraries that I can see.

    We are using Spread version 2.5.1007.2002.


     

     

     

  • Replied 8 September 2017, 1:54 pm EST

    HitTest is not in version 2.5.


     


    You could use the GetColumnHeaderCellFromPixel method on the SpreadView object.


     


     

  • Replied 8 September 2017, 1:54 pm EST

    Thanks, how do I get to the SpreadView object from my grid (FPSpread object)?

    I have searched the installed samples without any joy.  A SpreadView object just seems to be returned as a parameter in certain Spread events as far as I can see.

    EDIT - I have tried this but it doesn't work

    int rvi = ActiveGrid.GetActiveRowViewportIndex();

    int cvi = ActiveGrid.GetActiveColumnViewportIndex(); 

    SpreadView view = ActiveGrid.GetRootWorkbook().GetActiveWorkbook().GetSpreadView(ActiveGrid.ActiveSheet, rvi, cvi);

    _cellRangeMouseDown = view.GetColumnHeaderCellFromPixel (cvi, e.X, e.Y);

  • Replied 8 September 2017, 1:54 pm EST

    Lewis,

    Take a look at an earlier discussed thread.

    Thanks

  • Replied 8 September 2017, 1:54 pm EST

    I don't think this thread is the same issue. 

    EDIT - I have found an alternative solution now. 
Need extra support?

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

Learn More

Forum Channels