Opened 2 months ago

Closed 2 months ago

Last modified 2 months ago

#16399 closed defect (fixed)

Column titles incorrect when wxGrid::SetTable is used with native column header

Reported by: hajokirchhoff Owned by: VZ
Priority: normal Milestone: 3.0.2
Component: wxGrid Version: dev-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

Calling SetTable sets up column headers with numbers from 1 to n if UseNativeColumnHeader() is active. It should call the virtual method GetColLabelValue of the wxGridTableBase derived class, but it doesn't.

In src/generic/grid.cpp (svn-head), at line 2350 is the following code

 m_numRows = table->GetNumberRows();
 m_numCols = table->GetNumberCols();

 if ( m_useNativeHeader )
     GetGridColHeader()->SetColumnCount(m_numCols);

 m_table = table;

GetGridColHeader()->SetColumnCount is called before the member variable m_table is set. This is wrong. SetColumnCount will setup the columns of the native column header and call wxGrid::GetColLabelValue. Since m_table is not yet set, the derived method cannot be called and the default column titles are used instead.

Solution should be easy: Move the statement

 m_table = table;

up so that the variable is set before SetColumnCount is called.

Change History (2)

comment:1 Changed 2 months ago by VZ

  • Owner set to VZ
  • Resolution set to fixed
  • Status changed from new to closed

In 76975:

Correct wxGrid column labels when using SetTable() with native header.

Ensure that the table pointer inside wxGrid is updated before initializing the
native column header as it uses wxGrid::GetColLabelValue() which doesn't work
correctly without a valid table pointer.

Closes #16399.

comment:2 Changed 2 months ago by VZ

In 76976:

Correct wxGrid column labels when using SetTable() with native header.

Ensure that the table pointer inside wxGrid is updated before initializing the
native column header as it uses wxGrid::GetColLabelValue() which doesn't work
correctly without a valid table pointer.

Closes #16399.

Note: See TracTickets for help on using tickets.