Lock a column from drag & drop

Posted by: rene1983 on 8 September 2017, 2:13 pm EST

  • Posted 8 September 2017, 2:13 pm EST

    Is it possible to prevent a user from dragging and dropping the first column?

    Thanks!

  • Replied 8 September 2017, 2:13 pm EST

    Rene,

    You can use the ColumnDragMove event and set the Cancel parameter to True for the first column to prevent it from dragging as follows:

    Private Sub FpSpread1_ColumnDragMove(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.DragMoveEventArgs) Handles FpSpread1.ColumnDragMove

            If e.Index = 0 Then
                e.Cancel = True
            End If
    End Sub

    Thanks

  • Replied 8 September 2017, 2:13 pm EST

    That seems to work however, how can I prevent the 3rd column, for example, from moving to the location of the first column?
  • Replied 8 September 2017, 2:13 pm EST

    Hello,


    To prevent the user from dragging and dropping the column ,you need to lock that particular column and set the protect property to True (Protect property is by default True).



                fpSpread1.AllowDragDrop = true;
                fpSpread1.ActiveSheet.Protect = true;
                fpSpread1.ActiveSheet.Columns[0].Locked = true;


    Hope this will help you. Thanks.

  • Replied 8 September 2017, 2:13 pm EST

    That still allowed me to move the column but prevented me from entering data into that column.

    I'm using Spread version 5.0.3503.2008

    Thanks.

  • Replied 8 September 2017, 2:13 pm EST

    Rene,

    There is not a way to implement this before the user drops the moving
    column. You would need to use the ColumnDragMoveCompleted event & MoveColumn method of Spread and if
    the column is trying to be moved to a location that is not valid, you
    have full control to move the column back to it's original posistion or
    some other place in the Spread.This can be done as follows:

     Private Sub FpSpread1_ColumnDragMoveCompleted(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.DragMoveCompletedEventArgs) Handles FpSpread1.ColumnDragMoveCompleted
            If e.ToIndex < 1 Then
                FpSpread1.ActiveSheet.MoveColumn(e.FromIndex, e.ToIndex, True)
            End If
     End Sub

     

  • Replied 8 September 2017, 2:13 pm EST

    Hello Rene,


    We have added your request as feature request #99914400 and it will be taken care of in future release of Spread.


    Thanks.

  • Replied 8 September 2017, 2:13 pm EST

    Thanks, I did ultimately get it working by using your last suggestion.
Need extra support?

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

Learn More

Forum Channels