Re: [gtkmm] TreeView Sort



David Jensen wrote:
i have a TreeView sorting properly when clicking the column header.
how does one force a sort without the click, say after filling in the ListStore? in other words sort it before displaying or with sorted insertions.


Ok got it working. it seems the RefPtr<YourModel>set_sort_column() enables the column you want the initial sort on. This i didn't have. the TreeViewColumn->set_sort_column() does not enable a sort, it only defines the sort, it begins to make sense. :)

//default order of the columns
//ToDo: set by config
int DirList::columns[8] = {0, 1, 2, 3, 4, 5, 6, 7};
	
void
DirList::add_column(int i)
{
 int sort_col_id;
 int col_id = DirList::columns[i];
    switch (col_id) {
      case v_name: {
        tv.append_column("Filename", ls->dlc.name);
        sort_col_id = m_name;
***        ls->set_sort_column (col_id, Gtk::SORT_ASCENDING);
      }
      break;
      case v_size: {
        tv.append_column("Size", ls->dlc.size);
        sort_col_id = m_isize;
      }
      break;
... more cases

  Gtk::TreeViewColumn *tvc = tv.get_column(i);
***  tvc->set_sort_column (sort_col_id);
  if (col_id == v_name)
    tvc->set_sort_indicator(TRUE);
}


__David Jensen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]