i'm using wxGridTableBase to set grid table data,
becouse of my large data (store in postgres database).
but, i don't know how to refresh data, to get new
data from database.
i'v tried to reset table data(using SetTabel function),
but wxGrid do not allow more than 1 set table :
MyGridTableBase *table = MyGridTableBase(dataset);
grid->SetTable(table, TRUE);
i've tried to find documentation or function to update
wxGridTableBase, Unfortunately i still have no idea
to refresh wxGridTableBase data.
How to refresh/update data using wxGridTableBase ?.
thanks
sorry, i'm still confused.
why there is no simple function to refresh it
like grid->ResetTable(MyTable);
> Take a look at wxGridStringTable, make sure that you override the
> virtual functions. Also, be sure to implement all the InsertCols/Rows
> and Appends so that you send the appropriate wxGridTableMessage. I
> actually just have them all call the same function that finds out what
> the actual size of the grid is and sends a message as appropriate. This
> part you probably have, so to answer your question, refresh the grid by
> simply calling wxGrid::AppendCols(1) (or any of the other similiar
> functions) and this will call your DerivedGridTable::AppendCols which
> you can use to update the grid.
>
> John Labenski
>
Take a look at wxGridStringTable, make sure that you override the
That would probably make more sense, but it would also just be another
function you'd have to override. I've included below the code I use to
hold xy plot data. The rest of the program loads and deletes the plot
data structures so after something changes I just call
mygrid->AppendCols(1) which in turn calls UpdatePlotData which gets it's
info from the pointer passed to the table's contructor.
Hope this helps,
John Labenski
class WXDLLEXPORT wxGridPlotTable : public wxGridTableBase
{
public:
wxGridPlotTable() { wxASSERT(FALSE); }
wxGridPlotTable( wxPlotWindow *plot );
~wxGridPlotTable();
// these are pure virtual in wxGridTableBase
//
int GetNumberRows();
int GetNumberCols();
wxString GetValue( int row, int col );
void SetValue( int row, int col, const wxString& s );
bool IsEmptyCell( int row, int col );
// overridden functions from wxGridTableBase
//
bool UpdatePlotData();
void Clear() { UpdatePlotData(); }
bool InsertRows( size_t pos = 0, size_t numRows = 1 ) { return
UpdatePlotData(); }
bool AppendRows( size_t numRows = 1 ) { return UpdatePlotData();
}
bool DeleteRows( size_t pos = 0, size_t numRows = 1 ) { return
UpdatePlotData(); }
bool InsertCols( size_t pos = 0, size_t numCols = 1 ) { return
UpdatePlotData(); }
bool AppendCols( size_t numCols = 1 ) { return UpdatePlotData();
}
bool DeleteCols( size_t pos = 0, size_t numCols = 1 ) { return
UpdatePlotData(); }
void SetRowLabelValue( int row, const wxString& ) {}
void SetColLabelValue( int col, const wxString& ) {}
wxString GetRowLabelValue( int row );
wxString GetColLabelValue( int col );
private:
wxPlotWindow *m_plot;
int m_rows, m_cols;
DECLARE_DYNAMIC_CLASS( wxGridPlotTable )
};
bool wxGridPlotTable::UpdatePlotData()
{
if (!m_plot) return FALSE;
int rows = GetNumberRows();
if (rows > m_rows)
{
if ( GetView() )
{
wxGridTableMessage msg( this,
wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
0,
rows - m_rows );
GetView()->ProcessTableMessage( msg );
}
m_rows = rows;
}
else if (rows < m_rows)
{
if ( GetView() )
{
wxGridTableMessage msg( this,
wxGRIDTABLE_NOTIFY_ROWS_DELETED,
0,
m_rows - rows );
GetView()->ProcessTableMessage( msg );
}
m_rows = rows;
}
int cols = GetNumberCols();
if (cols > m_cols)
{
if ( GetView() )
{
wxGridTableMessage msg( this,
wxGRIDTABLE_NOTIFY_COLS_INSERTED,
0,
cols - m_cols );
GetView()->ProcessTableMessage( msg );
}
m_cols = cols;
}
else if (cols < m_cols)
{
if ( GetView() )
{
wxGridTableMessage msg( this,
wxGRIDTABLE_NOTIFY_COLS_DELETED,
0,
m_cols - cols );
GetView()->ProcessTableMessage( msg );
}
m_cols = cols;
}
return TRUE;
}
Thanks.