SpreadGrid Scroll Mouse Press Move

Posted by: quockhanhk15tpm on 16 June 2022, 7:22 pm EST

  • Posted 16 June 2022, 7:22 pm EST

    Hello

    I using GcSpreadGrid.
    How using Scroll by press and move mouse.
    I have set the properties
    PanningMode="VerticalOnly"
    BoundaryFeedbackMode="Split"

    Please help me.
  • Replied 19 June 2022, 8:49 pm EST

    Hi,

    Could you please provide some more information that What you want to achieve?
    Scroll by press and move mouse on Scroll-bar or cells?
    Scrolling By Pressing and moving mouse on scroll-bar already scrolls the SpreadGrid.
    If you are trying to scroll by pressing and moving mouse on cells, the selection behavior and editing will not work.
    If we understood wrong, then please correct us and clarify your requirement.

    Best Regards,
    Nitin.
  • Replied 20 June 2022, 6:46 pm EST

    Hi,

    nitin.sharma said:

    If you are trying to scroll by pressing and moving mouse on cells, the selection behavior

    Yes. I trying to scroll by pressing and moving mouse on cells.

    Please help me.

    Thanks
  • Marked as Answer

    Replied 21 June 2022, 2:25 am EST

    Hi,

    Thanks for the snapshot and clarification.

    In order to scroll by pressing and moving mouse on cell, you need to handle PreviewMouseDown, PreviewMouseMove and PreviewMouseUp event as:


    private void GcSpreadGrid1_PreviewMouseUp(object sender, MouseButtonEventArgs e)
    {
    _isDragging = false;
    }

    private void GcSpreadGrid1_MouseMove(object sender, MouseEventArgs e)
    {
    if(_isDragging & e.LeftButton == MouseButtonState.Pressed)
    {
    var hitTest = gcSpreadGrid1.HitTest(e.GetPosition(gcSpreadGrid1)) as CellHitTestInfo;

    if(hitTest !=null)
    {
    if (initialRow > hitTest.RowIndex & GetViewBottomRow() + 1 != gcSpreadGrid1.Rows.Count)
    gcSpreadGrid1.ShowRow(GetViewTopRow() + 1, VerticalPosition.Top);

    else if (initialRow < hitTest.RowIndex & GetViewTopRow() != 0)
    gcSpreadGrid1.ShowRow(GetViewBottomRow() - 1, VerticalPosition.Bottom);
    }
    e.Handled = true;
    }
    }
    private void GcSpreadGrid1_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    {
    _isDragging = true;

    var ht = gcSpreadGrid1.HitTest(e.GetPosition(gcSpreadGrid1)) as CellHitTestInfo;
    if(ht != null)
    initialRow = ht.RowIndex;
    }
    private int GetViewTopRow()
    {
    int topmostRow = 0;
    for (int row = 0; row < gcSpreadGrid1.Rows.Count; row++)
    {
    for (int col = 0; col < gcSpreadGrid1.Columns.Count; col++)
    {
    if (gcSpreadGrid1.IsCellInView(row, col))
    {
    topmostRow = row;
    row = gcSpreadGrid1.Rows.Count;
    break;
    }
    }
    }
    return topmostRow;
    }
    private int GetViewBottomRow()
    {
    int bottomMostRow = 0;
    for (int row = gcSpreadGrid1.Rows.Count-1; row >= 0; row--)
    {
    for (int col = 0; col < gcSpreadGrid1.Columns.Count; col++)
    {
    if (gcSpreadGrid1.IsCellInView(row, col))
    {
    bottomMostRow = row;
    row = -1;
    break;
    }
    }
    }
    return bottomMostRow;
    }


    Please refer the attached sample for the same : SpreadSample.zip

    Best Regards,
    Nitin.
  • Replied 21 June 2022, 1:27 pm EST

    Hi,

    Thanks for you answer.
    It's work.

    Regards
Need extra support?

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

Learn More

Forum Channels