If I create a custom Listbox class and add the events that I want to handle and then pass up to the subclassed control, How do I deal with the MouseDown, MouseUp, CellClick, and DoubleClick events so that each is properly handled?
I am currently using:
Return RaiseEvent(row, column, x, y)
In the customer super, but the CellClick and DoubleCliick events are not executing in the subclassed listbox.
// Event Definition
Public Event MouseDown(x As Integer, y As Integer) As Boolean
// Event Implementation
Public Function MouseDown(x As Integer, y As Integer) As Boolean
If RaiseEvent MouseDown(x, y) Then
// The event implementor does not want CustomListbox to further process the event
// which also means that it does not want Listbox to further process the event
Return True
End
// The event implementor does want CustomListbox to further process the event
...
Return False // or True if CustomListbox does not want Listbox to further process the event
// Event Definition
Public Event MouseDown(x As Integer, y As Integer) As Boolean
// Event Implementation
Public Function MouseDown(x As Integer, y As Integer) As Boolean
If RaiseEvent MouseDown(x, y) Then
// The event implementor does not want CustomListbox to further process the event
// which also means that it does not want Listbox to further process the event
Return True
End
// The event implementor does want CustomListbox to further process the event
...
Return False // or True if CustomListbox does not want Listbox to further process the event
End
End Class[/code][/quote]
That is a cleaner method of what I do, but I’m still not getting the CellClick if MouseDown is active. Are they mutually exclusive?
Yes - but now the MouseDrag event no longer fires.
Actually, it’s not different, just expanding the original question.
I guess that it’s an event order question based on Tim’s input above as well as Event dependency (i.e.: you must return True in MouseDown to get MouseUp to fire).
I’m trying to extend the ExcelGrid custom class that @Neil Burkholder provided in another thread so that I can mange drag cell selection as well standard CellClick and CellAction operations.
In my updating, I’ve added all of the Cell-related and Mouse-related events.
Not all mouse downs are the start of a drag. It can be the start of a single click to just select a cell, a double click, or the start of a drag. You need figure out which.
The best way I think would be to use timer started in Mousedown and return false for Mousedown
Use code in the timer (best a routine the teh listbox subclass assigned via AddHandler) to detect if a drag is happening (mouse is still down but you moved it a a at least a certain distance from initial mousedown). If so update the selection and invalidate the cells from there . Exit the timer routine on mouse up. If you want you can even have it call a mouseup event before it exits to generalize it.
There is still a lot of stuff missing and not like excel, but this should get you started. Oh there are probably bugs because I just threw this together for demonstration and didn’t really test it much.
Things that could be implemented yet.
Copy,cut,paste
Home, End, pageup/dn (shift)
Undo
Fill
Formulas
Fonts and text size/color
Column and row headers, (select, resize, insert, delete) - I would use the first row and column as the header so you have full control over mouse input and drawing.
Right click, context menu…
Embedded Pictures
The list (pun intended) goes on and on.
Things I have implemented:
Drawing and cell selection similar to excel. (I’ve positioned and sized the cell edit control so it’s at the correct location and doesn’t chop off the selection border.
Cell editing similar to Excel
Functioning of arrow keys, Enter, Tab, Delete, and backspace in grid as well as cell edit mode.
Moving acitve cell inside of selection via tab and enter.
Pressing enter after tabbing returns to starting column
Deleting multiple cells
Extend selection with shift+Arrow key
Drag selecting of cells works even if mouse is outside of the grid/window
EDIT: Before someone reminds me I DID NOT implement all the proper event definitions and raise them, although it wouldn’t be hard to do so.
Oh also it might get pretty slow with 16,384 columns and 1,048,576 rows
**A ListBox can only have up to 256 columns (index starts at 0), there would be 16,129 missing columns The number of rows would be determined by the system memory constraints (upwards ~ 2 billion rows in most use cases). On a side note, I don’t know of any Datagrid control that would support that many columns, in any programming language
An Excel like control should NOT be based on a “Listbox” control… as the storage mechanism should be a “SPARSE ARRAY”
so if A:1 is populated and ZZ:10000 is populated, your “array” has TWO entries, and all the empty space doesn’t take up storage space of any kind. And since you only see a few dozen columns and rows at any one time, you also remove the overhead of scrolling massive listboxes around.
Years ago I started playing with such a design… the presentation layer was a canvas, and the size of the sheet was techinically unlimited in both directions. FYI… this is similar to the method that Microsoft Excel actually uses
[quote=365746:@Dave S]An Excel like control should NOT be based on a “Listbox” control… as the storage mechanism should be a “SPARSE ARRAY”
so if A:1 is populated and ZZ:10000 is populated, your “array” has TWO entries, and all the empty space doesn’t take up storage space of any kind. And since you only see a few dozen columns and rows at any one time, you also remove the overhead of scrolling massive listboxes around.
Years ago I started playing with such a design… the presentation layer was a canvas, and the size of the sheet was techinically unlimited in both directions. FYI… this is similar to the method that Microsoft Excel actually uses[/quote]
That’s how our SimDesignerCanvas works Only what you see stays in memory… Dave is 100% correct.
Mimic the cumbersome and goofy Excel toolbar is probably difficult.
However, designing a grid is not that difficult to do. It is probably way simpler than trying to turn the listbox into a spreadsheet.
Note that Dan Bricklin originally created the first spreadsheet Visicalc in AppleSoft Basic. So it should not be out of this world to do a similar job in almighty, all modern Xojo