void MyFrame::OnOpen(wxCommandEvent & WXUNUSED(event)) { wxFileDialog dialog(this, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (dialog.ShowModal() == wxID_OK) { wxString filename(dialog.GetPath()); wxTextFile text_file(filename); if (!text_file.Open(wxConvUTF8)) { return; } grid->EnableEditing(false); if (text_file.GetLineCount() > grid->GetNumberRows()) { grid->AppendRows(text_file.GetLineCount() - grid->GetNumberRows()); } else if (text_file.GetLineCount() < grid->GetNumberRows()) { grid->DeleteRows(text_file.GetLineCount(), grid->GetNumberRows() - text_file.GetLineCount()); } grid->ClearGrid(); for (int row = 0; row < text_file.GetLineCount(); ++row) { wxStringTokenizer tokenizer(text_file[row], L","); for (int col = 0; tokenizer.HasMoreTokens() && col < grid->GetNumberCols(); ++col) { wxString token = tokenizer.GetNextToken(); grid->SetCellValue(row, col, token); } } grid->AutoSize(); text->Clear(); lines.clear(); for (int row = 0; row < text_file.GetLineCount(); ++row) { lines.push_back(text_file[row]); } text_file.Close(); topsizer->Layout(); SetStatusText(wxFileName(filename).GetFullName()); } }