wxGrid display large data

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
murali_hegde
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Sep 16, 2020 2:42 pm

wxGrid display large data

Post by murali_hegde » Wed Sep 16, 2020 2:54 pm

Hi,

I use wxwidgets to develop my c++ GUI application. I have to display around 150 rows data in wxGrid. I have derived a class from wxGrid in my application already. The grid has 10 columns. Now during Initialization of grid, i have to read data for all 150 rows, and show it in the grid, this is taking more time for me.

Is there any way to improve this somehow? currently it is taking more than 20s to display all 150 rows in grid. i thought of catching scroll event for grid, so that instead of reading all rows, i can read only current visible row. But i could not succeed in catching any scroll event in my grid derived class.

Basically my grid data display code is like below
for(int row = 0; row < GetNumberRows(); row++)
{
display_row_data(row);
}

The function display_row_data reads the data each row (the data is stored in another dll, which i query from one of the exposed method).


Can u provide some possible ways how i can split this read and display process in grid. ? How can i catch scroll event in Grid class? can u tell me the example code for this

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

Re: wxGrid display large data

Post by doublemax » Wed Sep 16, 2020 3:27 pm

I have to display around 150 rows data in wxGrid. I have derived a class from wxGrid in my application already. The grid has 10 columns. Now during Initialization of grid, i have to read data for all 150 rows, and show it in the grid, this is taking more time for me.
150 rows with 10 columns is nothing, this shouldn't take so long.

E.g. this code takes almost no time

Code: Select all

grid = new wxGrid(panel, wxID_ANY);
grid->CreateGrid(150, 10);

for( int row=0; row<150; row++)
{
  for( int col=0; col<10; col++ )
  {
    grid->SetCellValue(row, col, wxString::Format( wxT("cell %d, %d"), row, col ) );
  }
}
How are you loading the data? Can you show some code?

Try wrapping the loading code in Freeze()/Thaw() calls on the grid.
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2672
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxGrid display large data

Post by PB » Wed Sep 16, 2020 4:33 pm

What actually takes the those 2 seconds (or really 20?!) during wxGrid initialization, it certainly should not be anything in wxGrid itself, it must be the data loading?

BTW, in addition to generic Freeze()/Thaw() methods, there is wxGrid-specific wxGridUpdateLocker, see https://docs.wxwidgets.org/trunk/classw ... ocker.html

However, I do not think those would be of any help, they are supposed to help with flicker from multiple successive display updates.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4540
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxGrid display large data

Post by ONEEYEMAN » Wed Sep 16, 2020 6:59 pm

Hi,
Are you working with the Debug version of the library?

Thank you.

murali_hegde
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Sep 16, 2020 2:42 pm

Re: wxGrid display large data

Post by murali_hegde » Thu Sep 17, 2020 6:04 am

Hi,

Yes. After some analysis i found that the time is actually spent in reading the huge data but not with respect to the grid display itself.
The problem is, we do not have control over the data reading part. I am working with release builds only. Since do reading of data during display of the
grid, so until the complete data is read, i cannot display the grid on screen.
So i want to do the data display only for the current visible portion of the grid, since grid has scrollbar, as user scrolls the grid window, further rows are visible, and i will display further rows. WIth this i do not have to read entire data at once.

Can u share me some example code, how i can catch scroll event in grid, and know current visible rows and do grid->SetCellValue() only for those visible cells.?

The scrolling mechanism will at-least work for me for this problem.

If handling scrollbar is not a recommended way, then can splitting the data read part into multiple threads help ?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4540
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxGrid display large data

Post by ONEEYEMAN » Thu Sep 17, 2020 6:52 am

Hi,
Do you have to use wxGrid?
The way you want your program to work virtual wxListCtrl sounds like a way to go.

Also, I'm kind of curious - what do you mean by saying "We don't have control how the data read"?
Are you reading it from the DB? Text file? CSV file? Do you use some external library to read the data?

Thank you.

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

Re: wxGrid display large data

Post by doublemax » Thu Sep 17, 2020 8:09 am

After some analysis i found that the time is actually spent in reading the huge data but not with respect to the grid display itself.
I'm a little confused. How can 150 rows with 10 columns be "huge data"? Or do you mean 150.000? Or does each cell contain huge amounts of text?

And how can it be so slow? Are you getting the data over a slow network?

Anyway, assuming there is really nothing you can do about the data access, messing with scroll events etc. is not the way to go.

First of all, do you really need a wxGrid? Check if wxListCtrl might be sufficient for you. This would makes things much easier. Because like ONEEYEMAN said, you could then use a "virtual" wxListCtrl.

If you need a wxGrid, the way to solve this is to subclass wxGridTableBase:
https://docs.wxwidgets.org/trunk/classw ... _base.html
Use the source, Luke!

Post Reply