Right click drag & select in TAdvStringGrid

Hi,

I am trying to implement a behaviour in the TAdvStringGrid. So far I have mousedown, mousemove and mouseup and drawcell implementing my own custom solution where I store the startpoint (TPoint) and endpoint (TPoint) and draw a coloured background for the cells in between.

The problem I have is that the right click range select will not scroll the grid once I reach the rightmost or bottommost cells, like it does with the left-click range select.

Is there anyway to do this? I've tried ScrollInView(col, row) but the grid position appears to jump to fairly random positions and is not a good user experience.

Thanks
Stuart

Have you considered setting grid.MouseActions.SelectOnRightClick?

HI Bruno,

Yes, but unless I am missing something, this doesn't allow a range to be selected. It will select a single cell, but no drag-select for a range.

Hence why I have been implementing my own "range" code.

Thanks

Sorry, I overlooked that.
Letting the grid scroll when you are at the boundaries is not trivial.
To control grid scrolling programmatically , you can do this with the properties grid.TopRow / grid.LeftCol.
You would need to change these properties when you detect the user moves the mouse near the bottom or right border.

Hi Bruno - no worries :-)

Thanks - the toprow leftcol could be what I need - thanks :-)

For info: this code in the MouseMove seems to work nicely.

    // check for right mouse button in mouseDown event
    aGrid.MouseToCell(X,Y,aCol,aRow);
    if (aGrid.LeftCol > 0) and (aCol <= aGrid.LeftCol+1) and (aGrid.LeftCol > aGrid.FixedCols) then
      aGrid.LeftCol := aGrid.LeftCol-1
    else
    if (aCol >= aGrid.LeftCol+aGrid.VisibleColCount-1) and (aCol < aGrid.ColCount-1) then
      aGrid.LeftCol := aGrid.LeftCol + 1;

    if (aGrid.TopRow > 0) and (aRow <= aGrid.TopRow+1) and (aGrid.TopRow > aGrid.FixedRows) then
      aGrid.TopRow := aGrid.TopRow-1
    else
    if (aRow >= aGrid.TopRow+aGrid.VisibleRowCount-1) and (aRow < aGrid.RowCount-1) then
      aGrid.TopRow := AGrid.TopRow + 1;

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.