Does wxGrid support ReCreateGrid anyway? Topic is 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
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Does wxGrid support ReCreateGrid anyway?

Post by Ronald »

Data with variant row count and col count are to be read into wxGrid

wxGrid::CreateGrid failed when called twice or more

Tried to clear grids first as below, failed
  • Code: Select all

    wxGrid::ClearGrid()
  • Code: Select all

    int row_count = GetNumberRows();
    if (row_count > 0)
        DeleteRows(0, row_count, false);
    int col_count = GetNumberCols();
    if (col_count > 0)
        DeleteCols(0, col_count, false);
    
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Does wxGrid support ReCreateGrid anyway?

Post by ONEEYEMAN »

Hi,
What is an exact scenario that you need for re-creating wxGrid?

Thank you.
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Does wxGrid support ReCreateGrid anyway?

Post by Ronald »

ONEEYEMAN wrote:Hi,
What is an exact scenario that you need for re-creating wxGrid?
Excactly this is not necessary, the scenario:
1. wxGrid::CreateGrid is encapsulated in a function
2. The function would like to return false with logs when failing without terminating the program, this could not be implemented
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Does wxGrid support ReCreateGrid anyway?

Post by ONEEYEMAN »

Hi,
When the function will fail? Can we see some code please?
Are you creating the wxGrid in the same function where the data population occur?

Please check the grid sample to see how to make it work.

Thank you.
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Does wxGrid support ReCreateGrid anyway?

Post by Ronald »

ONEEYEMAN wrote:Hi,
When the function will fail?
When wxGrid::CreateGrid is called twice or more times for the same wxGrid.
For example, the same wxGrid is to filled by different data with different rows and cols.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Does wxGrid support ReCreateGrid anyway?

Post by doublemax »

Code: Select all

wxGrid::ClearGrid()

int row_count = GetNumberRows();
if (row_count > 0)
    DeleteRows(0, row_count, false);
int col_count = GetNumberCols();
if (col_count > 0)
    DeleteCols(0, col_count, false);
This code works for me. What happens when you execute it? Did you call Refresh() afterwards to see the changes?
Use the source, Luke!
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Does wxGrid support ReCreateGrid anyway?

Post by Ronald »

doublemax wrote:

Code: Select all

wxGrid::ClearGrid()

int row_count = GetNumberRows();
if (row_count > 0)
    DeleteRows(0, row_count, false);
int col_count = GetNumberCols();
if (col_count > 0)
    DeleteCols(0, col_count, false);
This code works for me. What happens when you execute it? Did you call Refresh() afterwards to see the changes?
What's in need is to recreate grids with different size

1. Not work

Code: Select all

wxGrid::CreateGrid()

wxGrid::ClearGrid()

wxGrid::CreateGrid() // not work
2. Not work

Code: Select all

wxGrid::CreateGrid()

int row_count = GetNumberRows();
if (row_count > 0)
    DeleteRows(0, row_count, false);
int col_count = GetNumberCols();
if (col_count > 0)
    DeleteCols(0, col_count, false);
    
wxGrid::CreateGrid() // not work
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Does wxGrid support ReCreateGrid anyway?

Post by ONEEYEMAN »

Hi,
If its just a different size if the grid - why not use Append{Row,Col} functions?
On top of everything it will be faster than re-creating the whole grid...

Thank you.
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: Does wxGrid support ReCreateGrid anyway?

Post by Ronald »

ONEEYEMAN wrote:Hi,
If its just a different size if the grid - why not use Append{Row,Col} functions?
In this way, 6 cases to consider: add/keep/remove rows/cols. However it achieves a good result.

In fact I'm find something like: wxGrid::DestroyGrid/wxGrid::ResizeGrid, it seems that I have to implement it.
Post Reply