Creating a custom ListBox class and handling subclassed events

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.

Ideas or pointers?

Did you create corresponding Event Definitions?

Do you have code in the instance on the window?

[code]Class CustomListbox Inherits 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

End

End Class[/code]

Yes

Yes

[quote=356407:@Eli Ott][code]Class CustomListbox Inherits 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

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?

That is a completely different question compared to your initial post.

Why don’t you post the code of the two events?

I believe MouseDown fires first, so if you return True from MouseDown, you will not get a CellClick event. Otherwise, you should get both.

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.

  • karen

You guys make this sound so hard :wink:

I wouldn’t use a timer unless absolutely necessary.

Here is an updated example to give you some ideas.
https://www.dropbox.com/s/i471o2dfburd8fu/Excel%20Grid%20(test).xojo_binary_project?raw=1

I’ve implemented basic selection and editing.

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.

  1. Copy,cut,paste
  2. Home, End, pageup/dn (shift)
  3. Undo
  4. Fill
  5. Formulas :wink:
  6. Fonts and text size/color
  7. 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.
  8. Right click, context menu…
  9. Embedded Pictures
  10. The list (pun intended) goes on and on.

Things I have implemented:

  1. 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.
  2. Cell editing similar to Excel
  3. Functioning of arrow keys, Enter, Tab, Delete, and backspace in grid as well as cell edit mode.
  4. Moving acitve cell inside of selection via tab and enter.
  5. Pressing enter after tabbing returns to starting column
  6. Deleting multiple cells
  7. Extend selection with shift+Arrow key
  8. 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 :slight_smile:

**A ListBox can only have up to 256 columns (index starts at 0), there would be 16,129 missing columns :slight_smile: 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 :slight_smile:

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 :slight_smile: Only what you see stays in memory… :slight_smile: Dave is 100% correct.

Lol, It’s the spreadsheet king, Excel. The intent was to mimic Excel, which I was trying to say, would be nearly impossible.

Why? Microsoft did it…

Give me a day :-p

Yeah nothing is impossible but probably I wouldn’t try to use a list box :wink:

Here is a post outlining the concept. (Sorry it’s not a Xojo)

https://www.codeproject.com/Articles/34405/WPF-Data-Virtualization

The difficult I do immediately
The Impossible might take me all day

[quote=365755:@Dave S]The difficult I do immediately
The Impossible might take me all day[/quote]

I’m hiring. :slight_smile:

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 :wink: