Multiple Cell Selection in Listbox with MouseDrag

I’ve been digging through the ListBox examples and watching “Good Guy Listbox”, but I don’t see an example of rubberband selection of cells such as we can do with Numbers/Excel.

The idea being that the user could start a mousedown and drag from one Cell to another cell with a rectangle of cells being selected between the mousedown and mouseup events.

Has anyone done something like this?

[quote=355653:@Tim Jones]I’ve been digging through the ListBox examples and watching “Good Guy Listbox”, but I don’t see an example of rubberband selection of cells such as we can do with Numbers/Excel.

The idea being that the user could start a mousedown and drag from one Cell to another cell with a rectangle of cells being selected between the mousedown and mouseup events.

Has anyone done something like this?[/quote]

Not exactly but it can be done

If you want to show an outline of the selection box it would be more complicated but I think would be doable… If you just wanted to highlight the cells touched by the the rectangle without showing the rectangle that would be easier.

Pretty easy. Just use the mousedrag event.

Here is an example I just whipped up to give you an idea. https://www.dropbox.com/s/i471o2dfburd8fu/Excel%20Grid%20(test).xojo_binary_project?raw=1

Hi Neil and Karen,

Thanks. That’s the route I was looking at, but I was waiting and depending on the tracking of the ending row and column. Handling the selection one cell at a time makes it work as the user drags and I don’t need to draw a rubberband of the selection as Karen mentions.

It seems like there should be a more efficient way to invalidate cells than looping through them all.

InvalidateCell(-1,-1) doesn’t work right as documented. Plain invalidate doesn’t do the trick either.

[quote=355668:@Tim Jones]Hi Neil and Karen,

Thanks. That’s the route I was looking at, but I was waiting and depending on the tracking of the ending row and column. Handling the selection one cell at a time makes it work as the user drags and I don’t need to draw a rubberband of the selection as Karen mentions.[/quote]

BTW if are going to do such a UI, you should probably also allow doing such a selection by holding the shift key down and using the arrow keys.

[quote=355669:@Neil Burkholder]It seems like there should be a more efficient way to invalidate cells than looping through them all.
[/quote]

No, that is best.

  • karen

The example project I attached does handle that.

[quote=355669:@Neil Burkholder]It seems like there should be a more efficient way to invalidate cells than looping through them all.

InvalidateCell(-1,-1) doesn’t work right as documented. Plain invalidate doesn’t do the trick either.[/quote]
And - it’s not a process hog since the user will only be doing in once in a while and maybe evern never once the configuration is done during initial setup.

i have created this opensource project–> ExcelListbox - Help needed - Little Opensource project - General - Xojo Programming Forum
i have also created this feedback case–> <https://xojo.com/issue/47545>

if someone wants to contribute, we could create a listbox that behaves like excel!!

[quote=355665:@Neil Burkholder]Pretty easy. Just use the mousedrag event.

Here is an example I just whipped up to give you an idea. https://www.dropbox.com/s/i471o2dfburd8fu/Excel%20Grid%20(test).xojo_binary_project?raw=1[/quote]

Very nice. Just one tiny bug when you drag into the empty rows. To fix (I commented out the original code and replaced it with four lines):

[code]Sub MouseDrag(x As Integer, y As Integer) Handles MouseDrag
If Not Dragging Then Dragging = True
Dragging = False

’ SelEndRow = RowFromXY(x,y)
’ SelEndCol = ColumnFromXY(x,y)

dim row as integer = RowFromXY(x,y)
dim col as integer = ColumnFromXY(x,y)
if row > -1 then SelEndRow = row
if col > -1 then SelEndCol = col

InvalidateAllCells
RaiseEvent MouseDrag(x,y)
End Sub[/code]

I’m now working on this to allow the drag-selection as well as single click selection to work as I also need to interact with the CellCheck event. The management of Event Order and Event dependencies is turning out to be a true rat’s nest of code.

Short of trial and error, does anyone have a list that provides a hierarchy tree for the dependencies and order?

See my post in the other thread

  • Karen

I had just thrown that together quick for an example. The code below actually allows selecting while the mouse is outside the grid.

Sub MouseDrag(x As Integer, y As Integer) Handles MouseDrag
  Dim row As Integer = RowFromXY(1,y)
  Dim col As Integer = ColumnFromXY(x,HeaderHeight+1)
  If col > ColumnCount-1 Then col = -1 'because columns greater than column count can be returned
  If row > -1 Then SelEndRow = row
  If col > -1 Then SelEndCol = col
  InvalidateAllCells
  RaiseEvent MouseDrag(x,y)
End Sub

For the complete project see the discussion here.