I've made an editable TreeView Component with a ListStore Model. I need to be able to tell when a cell is edited (via signal_edited), what the name of the column is thats throwing the signal and data of other columns in the same row. My Program recieves its data from MySQL and will be modifying the data in the database as well.
I'm using Gtkmm 2.4 on Windows XP using MSVC++ 2005 express edition. A code example in either Gtk+ or Gtkmm will work, but Gtkmm is prefered.
Setting up the signals for the columns:
Code:
// set column properties
for (unsigned int x=0; x<m_TreeView.get_columns().size(); x++)
{
m_TreeView.get_column(x)->set_reorderable();
m_TreeView.get_column(x)->set_clickable();
m_TreeView.get_column(x)->set_resizable();
m_TreeView.get_column(x)->set_sort_column(x);
// Get the column and connect a signal to it
Gtk::CellRendererText * rendererText =
dynamic_cast<Gtk::CellRendererText *>(m_TreeView.get_column_cell_renderer(x));
rendererText->signal_edited().connect(sigc::mem_fun(*this, &CMainWindow::OnCellEdited));
}
My failed attempts for OnCellEdited():
Code:
void CMainWindow::OnCellEdited(const Glib::ustring& path_string, const Glib::ustring& new_text)
{
std::cout << "Cell Edited: Original: "<< path_string << " Edited: " << new_text << "\n";
Gtk::TreeModel::iterator iter = m_TreeView.get_selection()->get_selected();
/*
{
Gtk::TreeModel::Row row = *RowIter;
std::vector<std::string *> ColumnValues;
for(unsigned int i=1; i<m_TreeView.get_columns().size(); i++)
{
ColumnValues.push_back(
new std::string(
(*iter)[m_Columns.m_col_last_name]
)
);
}
*/
/* Gtk::TreeModel::iterator iter = m_TreeView.get_selection()->get_selected();
if (iter)
{
Gtk::TreeModel::Row row = *iter;
// Don't know how to grab the current column edited so just grabbing all
// columns and altering whole row, should only add slight overhead to database
ColumnValues.push_back(new std::string(row->get_value(m_Columns.m_col_last_name) ) );
ColumnValues.push_back(new std::string(row->get_value(m_Columns.m_col_first_name) ) );
ColumnValues.push_back(new std::string(row->get_value(m_Columns.m_col_middle_init) ) );
ColumnValues.push_back(new std::string(row->get_value(m_Columns.m_col_gender) ) );
ColumnValues.push_back(new std::string(row->get_value(m_Columns.m_col_phone) ) );
ColumnValues.push_back(new std::string(row->get_value(m_Columns.m_col_email) ) );
ColumnValues.push_back(new std::string(row->get_value(m_Columns.m_col_company) ) );
std::cout << row->get_value(m_Columns.m_col_id) << " ";
for(int i=0; i<ColumnValues.size(); i++)
std::cout << ColumnValues.at(i) << " ";
std::cout << std::endl;
//database.EditRow(row->get_value(m_Columns.m_col_id), ColumnValues);
*/
}