wxdbgridtablebaseyou can view a database table in a grid using this class. if you are deriving your own wxdbtable subclass for your table , then you may consider overriding getcol() and setcol() to provide calculated fields. this does work but care should be taken when using wxdbgridtablebase in this way. the constructor and assigndbtable() call allows you to specify the ownership if the wxdbtable object pointer. if you tell wxgridtablebase to take ownership , it will delete the passed wxdbtable when an new on is assigned or wxgridtablebase's destructor is called. however no checks for aliasing are done so assign(table,..,true); assign(table,..,true); is an error. if you need to requery an table object the preferred way is that the client keeps ownership. derived from include files <wx/dbgrid.h> example
// first step, let's define wxdbtable int numcolumns = 2; wxdbtable *table = new wxdbtable (db, tblname, numcolumns); int int_var; wxchar string_name[255]; table->setcoldef (0, "column 0", db_data_type_integer, &int_var, sql_c_long, sizeof(int_var), true); table->setcoldef (1, "column 1", db_data_type_varchar, &string_name, sql_c_long, sizeof(string_name), false); // now let's define columns in the grid // first way to do it wxdbgridcolinfo *columns; columns = new wxdbgridcolinfo(0, wxgrid_value_long, "first column", new wxdbgridcolinfo(1, wxgrid_value_string, "second column", null); // second way to do it wxdbgridcolinfo *columns; // first column is special columns = new wxdbgridcolinfo(0, wxgrid_value_long, "first column", null); // all the rest columns->addcolinfo (1, wxgrid_value_string, "second column"); // second way may be better when columns are not known at compile time // now, let's open the table and make a query() table->open(); // this step is very important table->setrowmode (wxdbtable::wx_row_mode_query); // in the grid we will see only the rows of the result query m_dbtable->query(); wxdbgridtablebase *dbgrid = new wxdbgridtablebase(table, columns, wxuse_query, true); delete columns; // not needed anymore wxgrid *grid = new wxgrid ( ... ); grid->settable(dbgrid, true); grid->fit();include files <wx/dbgrid.h> helper classes and data structures
wxdbgridtablebase::wxdbgridtablebase
wxdbgridtablebase::wxdbgridtablebasewxdbgridtablebase(wxdbtable *tab, wxdbgridcolinfo *colinfo, int count = wxuse_query, bool takeownership = true) constructor. parameters tab
takeownership
wxdbgridtablebase::validaterowvoid validaterow(int row) it ensures that the row data is fetched from the database, and it the wxdbtable local buffer, the row number passed should be the grid row. parameters row
wxdbgridtablebase::updaterowbool updaterow(int row) if row has changed it forces that row to be written back to the database, however support for detecting whether insert/update is required is currently not in wxdbtable, so this function is currently unsupported. parameters row
wxdbgridtablebase::assigndbtablebool assigndbtable(wxdbtable *tab,int count = wxuse_query, bool takeownership = true) resets the grid for using with a new database table, but using the same columns definition. this can be useful when re-querying the database and want to see the changes. parameters tab
|