Overriding wxGrid scroll actions [Solved]

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Tony0945
Experienced Solver
Experienced Solver
Posts: 96
Joined: Wed Oct 21, 2009 4:02 pm

Overriding wxGrid scroll actions [Solved]

Post by Tony0945 » Wed Jan 20, 2016 3:14 am

I have a wxGrid that is a 3 x 5 window into a much larger table, most of which probably would not be accessed in any given program incarnation.

I want to override the scrollbar events so as to generate the cells that are coming into view.

In the dialog constructor, I have tried this:

Code: Select all

	ProgramGrid->SetLabelFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, false));
	ProgramGrid->Bind(wxEVT_SCROLLWIN_LINEUP,ProgramGuideDialog::OnGridScroll,this);
Which generates the error message
80 C:\_WXDEV-CPP Projects\Oregano\ProgramGuideDlg.cpp:153 no matching function for call to 'wxGrid::Bind(const wxEventTypeTag<wxScrollWinEvent>&, <unresolved overloaded function type>, ProgramGuideDialog* const)'
However the overloaded function should be resolved as it is defined in the header thusly

Code: Select all

class ProgramGuideDialog : public wxDialog
{
	private:
		DECLARE_EVENT_TABLE();

	public:
		ProgramGuideDialog(wxWindow *parent, wxWindowID id = 1, const wxString &title = wxT("Program Guide"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = ProgramGuideDialog_STYLE);
		virtual ~ProgramGuideDialog();
		void OnGridScroll(wxScrollEvent& event);
		void ProgramGridCellLeftClick(wxGridEvent& event);
		void ProgramGridCellRightClick(wxGridEvent& event);
I'm using the Bind method because I had a similar error message trying to use an event macro.

I've considered sub-classing but delving deep into the wxGrid code, I don't see any virtual event handler.

I just want to catch the events, generate the data, then call event.Skip() to continue with the normal scrolling actions.

Or is there a better way to handle this? I originally had standalone scollbars which worked well, but were rather ugly compared to the built-in scrollbars.
Last edited by Tony0945 on Wed Jan 20, 2016 5:43 pm, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 14525
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Overriding wxGrid scroll actions

Post by doublemax » Wed Jan 20, 2016 10:35 am

wxScrollEvent and wxScrollWinEvent are not the same.
Use the source, Luke!

Tony0945
Experienced Solver
Experienced Solver
Posts: 96
Joined: Wed Oct 21, 2009 4:02 pm

Re: Overriding wxGrid scroll actions

Post by Tony0945 » Wed Jan 20, 2016 4:19 pm

Changed wxScrollEvent to wxScrollWinEvent and got the same message. Maybe there isn't any way to do this.

Edit: The Bind() call won't compile, but I did manage to add EVT_SCROLLWIN(ProgramGuideDialog::OnGridScroll) to the event table. Unfortunately, the event handler isn't called. I extended the 3x5 table to a 4x6 and the scroll bars work fine, but OnGridScroll is never called.

I may have to generate data for the complete matrix which is 672x78 but I hate to do it because it will take a lot of memory and a lot of time to calculate the data.
Last edited by Tony0945 on Wed Jan 20, 2016 5:39 pm, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 14525
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Overriding wxGrid scroll actions

Post by doublemax » Wed Jan 20, 2016 5:35 pm

Try:

Code: Select all

ProgramGrid->Bind(wxEVT_SCROLLWIN_LINEUP, &ProgramGuideDialog::OnGridScroll, this);
Use the source, Luke!

Tony0945
Experienced Solver
Experienced Solver
Posts: 96
Joined: Wed Oct 21, 2009 4:02 pm

Re: Overriding wxGrid scroll actions

Post by Tony0945 » Wed Jan 20, 2016 5:42 pm

That one works! Thanks a million, doublemax!

Post Reply