+#if wxUSE_GRID
+
+BEGIN_EVENT_TABLE(DbGridFrame, wxFrame)
+ // EVT_CLOSE(DbGridFrame::OnCloseWindow)
+END_EVENT_TABLE()
+
+
+DbGridFrame::DbGridFrame(wxWindow *parent)
+ : wxFrame (parent, wxID_ANY, wxT("Database Table"),
+ wxDefaultPosition, wxSize(400, 325))
+{
+ initialized = false;
+}
+
+
+void DbGridFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
+{
+ this->Destroy();
+}
+
+
+bool DbGridFrame::Initialize()
+{
+ wxGrid *grid = new wxGrid(this, wxID_ANY, wxDefaultPosition);
+
+ grid->RegisterDataType(wxGRID_VALUE_DATETIME,
+ new wxGridCellDateTimeRenderer(wxT("%d %b %Y")),
+ new wxGridCellTextEditor);
+#ifdef CHOICEINT
+ grid->RegisterDataType(wxGRID_VALUE_CHOICEINT,
+ new wxGridCellEnumRenderer,
+ new wxGridCellEnumEditor);
+
+ wxString NativeLangChoice( wxString::Format(wxT("%s:%s,%s,%s,%s,%s"),wxGRID_VALUE_CHOICEINT,
+ wxT("English"),
+ wxT("French"),
+ wxT("German"),
+ wxT("Spanish"),
+ wxT("Other") ));
+#endif
+
+ // Columns must match the sequence specified in SetColDef() calls
+ wxDbGridColInfo* cols =
+ new wxDbGridColInfo( 0,wxGRID_VALUE_STRING,wxT("Name"),
+ new wxDbGridColInfo( 1,wxGRID_VALUE_STRING,wxT("Address 1"),
+ new wxDbGridColInfo( 2,wxGRID_VALUE_STRING,wxT("Address 2"),
+ new wxDbGridColInfo( 3,wxGRID_VALUE_STRING,wxT("City"),
+ new wxDbGridColInfo( 4,wxGRID_VALUE_STRING,wxT("State"),
+ new wxDbGridColInfo( 5,wxGRID_VALUE_STRING,wxT("PostCode"),
+ new wxDbGridColInfo( 6,wxGRID_VALUE_STRING,wxT("Country"),
+ new wxDbGridColInfo( 7,wxGRID_VALUE_DBAUTO,wxT("Join Date"),
+ new wxDbGridColInfo( 8,wxGRID_VALUE_BOOL, wxT("Developer"),
+ new wxDbGridColInfo( 9,wxGRID_VALUE_NUMBER,wxT("Contributions"),
+ new wxDbGridColInfo(10,wxGRID_VALUE_NUMBER,wxT("Lines Of Code"),
+#ifdef CHOICEINT
+ new wxDbGridColInfo(11,NativeLangChoice, wxT("Native Language"),NULL))))))))))));
+#else
+ new wxDbGridColInfo(11,wxGRID_VALUE_NUMBER,wxT("Native Language"),NULL))))))))))));
+#endif
+
+ Ccontact *Contact = new Ccontact();
+ //wxGetApp().Contact
+
+ if (!Contact)
+ {
+ wxMessageBox(wxT("Unable to instantiate an instance of Ccontact"), wxT("Error..."), wxOK | wxICON_EXCLAMATION);
+ return false;
+ }
+
+ if (!Contact->Open())
+ {
+ if (Contact->GetDb()->TableExists(CONTACT_TABLE_NAME, Contact->GetDb()->GetUsername(),
+ wxGetApp().DbConnectInf->GetDefaultDir()))
+ {
+ wxString tStr;
+ tStr.Printf(wxT("Unable to open the table '%s'.\n\n"),CONTACT_TABLE_NAME.c_str());
+ wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__TFILE__,__LINE__),
+ wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+ }
+
+ return false;
+ }
+
+ // Execute the following query using the cursor designated
+ // for full table query
+ Contact->SetRowMode(wxDbTable::WX_ROW_MODE_QUERY);
+
+ if (!Contact->Query())
+ {
+ wxString tStr;
+ tStr = wxT("ODBC error during Query()\n\n");
+ wxMessageBox(wxDbLogExtendedErrorMsg(tStr.c_str(),wxGetApp().Contact->GetDb(),__TFILE__,__LINE__),
+ wxT("ODBC Error..."),wxOK | wxICON_EXCLAMATION);
+ return false;
+ }
+
+ // No data has been read in from the database yet, so
+ // we need to initialize the data members to valid values
+ // so Fit() can correctly size the grid
+ Contact->Initialize();
+
+ wxDbGridTableBase* db = new wxDbGridTableBase(Contact, cols, wxUSE_QUERY, true);
+
+ delete cols;
+
+ grid->SetTable(db,true);
+ grid->SetMargins(0, 0);