wxGrid plus wxGridTableBase full table refresh

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
wxotichna
Earned a small fee
Earned a small fee
Posts: 19
Joined: Fri Sep 16, 2022 8:37 am

wxGrid plus wxGridTableBase full table refresh

Post by wxotichna »

Good morning

I have a wxGrid and a class that extends wxGridTableBase to provide the data for the wxGrid

it works as expected up to setting columns count and columns labels, adding values BEFORE view->SetTable(model); meaning that if I add two items the gui will show two items.

Once on screen, if I change the data model and call SetTable(newmodel) it will refresh the gui only when I manually change the size of the window.

I cannot find the right method to trigger that behaviour using the code

Anyone can help ?

Thank you
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: wxGrid plus wxGridTableBase full table refresh

Post by doublemax@work »

Did you try Refresh() ?
wxotichna
Earned a small fee
Earned a small fee
Posts: 19
Joined: Fri Sep 16, 2022 8:37 am

Re: wxGrid plus wxGridTableBase full table refresh

Post by wxotichna »

Yes, tried both

Code: Select all

	viewP->GetGridWindow()->Refresh();

	viewP->Refresh();
viewP is the pointer to wxGrid gui object
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: wxGrid plus wxGridTableBase full table refresh

Post by doublemax@work »

The code must not be inside a BeginBatch/EndBatch block or with an active wxGridUpdateLocker.

If that's already the case, try topsizer->Layout() or topwindow->SendSizeEvent()
wxotichna
Earned a small fee
Earned a small fee
Posts: 19
Joined: Fri Sep 16, 2022 8:37 am

Re: wxGrid plus wxGridTableBase full table refresh

Post by wxotichna »

no, the code was not in the Begin - End Batch

I ended up trying all methods that seemed reasonable and found the "right" one, so, if you want to change the data model of a wxGrid you do

Code: Select all

	viewP->SetTable(this);
	viewP->UpdateGridWindows();
from whithin the class that extends wxGridTableBase and viewP is a wxGrid instance

It would be nice to have some documentation about it, apparently, there are quite a few people looking for this information
wxotichna
Earned a small fee
Earned a small fee
Posts: 19
Joined: Fri Sep 16, 2022 8:37 am

Re: wxGrid plus wxGridTableBase full table refresh

Post by wxotichna »

Ok, status update, UpdateGridWindows actually does NOT solve the issue, but ... there is another "solution"

Rant mode on:
Can I just say that I wish ALL the "new and smart person" that comes up with some WONDERFUL idea to evaluate FIRST what has already been done before ? The pattern is as follows: "I have this new toy that solves this issue magically, you ALL must use it" and sheeple just jump on it.
python .... ahhhhhhh..... the magic snake, wonderful to write 10 lines of code and then FORGET about them. Take any minimal size application and it will be an unexploded bomb after the first week
wxWidget GUI is .... well, inventing a mostly round wheel .... whatever...
--------------- end rant mode

So, the apparent solution here is to change column width ... yes, the reason why I had a "working" solution is that I had other part of code to do a column resize when I did update the table content... and, it need to be a different value at each column, otherwise it will not work.

Can I say crap ?
wxotichna
Earned a small fee
Earned a small fee
Posts: 19
Joined: Fri Sep 16, 2022 8:37 am

Re: wxGrid plus wxGridTableBase full table refresh

Post by wxotichna »

some more info on having a table refresh when changing data source

Code: Select all

    	const int defColsize = GetDefaultColSize();
the colSize you are going to set must be different than the default, otherwise the magic will not work

Can I say that there should be a method for wxGrid refresh and one for wxRow refresh ?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxGrid plus wxGridTableBase full table refresh

Post by PB »

I am not really familiar with wxGrid, so I am not even sure you can change its table, since SetTable() docs say (emphasis mine).
This should be called after the grid constructor and before using the grid object.
Be that as it may, I assume you tried not only wxGrid::RefreshBlock() but also wxGrid::ForceRefresh() (this one should be used instead of Refresh()) but neither worked?

Either way, if you have a feature suggestion or a bug report, I recommend using wx-dev discussion group since that is the place where you can reach the developers.

See also https://github.com/wxWidgets/wxWidgets/pull/22826
Post Reply