OK got it my code now is:
Gtk::ListViewText::SelectionList sellst =
m_listviewtextAvailable->get_selected();
if(sellst.empty()) return;
Glib::RefPtr<Gtk::TreeSelection> ts =
m_listviewtextAvailable->get_selection();
Gtk::TreeModel::iterator sel_it = ts->get_selected();
int sel = sellst[0];
Glib::ustring selrow = m_listviewtextAvailable->get_text(sel);
m_listviewtextOrderBy->append(selrow);
//erase(sel_it);
Glib::RefPtr<Gtk::TreeModel> reftm =
m_listviewtextAvailable->get_model();
Glib::RefPtr<Gtk::TreeStore> refStore =
Glib::RefPtr<Gtk::TreeStore>::cast_dynamic(reftm);
if(refStore){
std::cout << __FILE__ << '[' << __LINE__ << "] it's a
Gtk::TreeStore" << std::endl;
refStore->erase(sel_it);
return;
}
Glib::RefPtr<Gtk::ListStore> refLStore =
Glib::RefPtr<Gtk::ListStore>::cast_dynamic(reftm);
if(refLStore){
std::cout << __FILE__ << '[' << __LINE__ << "] it's a
Gtk::ListStore" << std::endl;
refLStore->erase(sel_it);
}
That works and my model turns out to be a Gtk::ListStore I found some
code here
https://developer.gnome.org/gtkmm-tutorial/3.4/chapter-refptr.html.en
in particular
https://developer.gnome.org/gtkmm-tutorial/3.4/sec-refptr-casting.html.en
On 27/05/13 21:29, Francis (Grizzly) Smit wrote:
> On 27/05/13 21:13, Juan Angel Moreno wrote:
>>
>> Sorry, you must do Yor_Model->erase(sel_it);
>> erase() comes from Gtk::ListStore and from Gtk::TreeModel.
> my code now is:
>
> Gtk::ListViewText::SelectionList sellst =
> m_listviewtextAvailable->get_selected();
> if(sellst.empty()) return;
> Glib::RefPtr<Gtk::TreeSelection> ts =
> m_listviewtextAvailable->get_selection();
> Gtk::TreeModel::iterator sel_it = ts->get_selected();
> int sel = sellst[0];
> Glib::ustring selrow = m_listviewtextAvailable->get_text(sel);
> //erase(sel_it);
> *(m_listviewtextAvailable->get_model())->erase(sel_it);
>
>
> and I get thye following compiler error:
>
> /home/grizzlysmit/Projects/xmms2/cathy/src/dialog-new-playlist.cc:221:43:
> error:
> ‘class Gtk::TreeModel’ has no member named ‘erase’
>
> what am I doing wrong :(
>
>
>> Greetings.
>>
>>
>> 2013/5/27 Francis (Grizzly) Smit <[email protected]
>> <mailto:[email protected]>>
>>
>> On 27/05/13 17:20, Juan Angel Moreno wrote:
>>> For the selected row, use get_selection(), get_selected() and
>>> with the iterator returned by get_selected(), use erase(iterator).
>>> For an arbitrary row, iterate over the rows of your model with
>>> your_model->children().begin(), your_model->children().end(),
>>> etc. and use erase() on the iterator you want.
>> umm where does the erase function come from, I did this
>>
>> Gtk::ListViewText::SelectionList sellst =
>> m_listviewtextAvailable->get_selected();
>> if(sellst.empty()) return;
>> Gtk::TreeModel::iterator sel_it =
>> m_listviewtextAvailable->get_selection()->get_selected();
>> int sel = sellst[0];
>> Glib::ustring selrow = m_listviewtextAvailable->get_text(sel);
>> erase(sel_it);
>>
>> and I get a compile error on erase the compiler cannot find it??
>>
>>
>>> Greetings
>>>
>>>
>>> 2013/5/27 Francis (Grizzly) Smit <[email protected]
>>> <mailto:[email protected]>>
>>>
>>> Yeah I have been trying to delete a row in a
>>> Gtk::ListViewText, but I
>>> cannot find a member function to do this, I have tried the
>>> following
>>>
>>> guint num_cols = get_num_columns();
>>> guint num_rows = size();
>>> Glib::ustring result;
>>> if(num_cols == 1){
>>> std::vector<Glib::ustring> tmp;
>>> for(int r = 0; r < num_rows; r++){
>>> if(r == row){
>>> result = get_text(r);
>>> }else{
>>> tmp.insert(tmp.end(), get_text(r));
>>> }
>>> }
>>> remove_all_columns();
>>> guint n = tmp.size();
>>> for(int r = 0; r < n; r++){
>>> append(tmp[r]);
>>> }
>>> }else{
>>> std::vector<std::vector<Glib::ustring> > tmp;
>>> std::vector<Glib::ustring> t;
>>> for(int r = 0; r < num_rows; r++){
>>> if(r == row){
>>> result = get_text(r);
>>> }else{
>>> t.insert(t.end(), get_text(r));
>>> for(int c = 1; c < num_cols; c++){
>>> t.insert(t.end(), get_text (r, c));
>>> }
>>> tmp.insert(tmp.end(), t);
>>> }
>>> }
>>> remove_all_columns();
>>> guint n = tmp.size();
>>> for(int r = 0; r < n; r++){
>>> guint _r = append(tmp[r][0]);
>>> guint m = tmp[r].size();
>>> for(int c = 1; c < num_cols && c < m; c++){
>>> set_text(_r, c, tmp[r][c]);
>>> }
>>> }
>>> }
>>>
>>> but the remove_all_columns(); is too drastic I loose every
>>> thing and can
>>> no longer put the rows I want to keep back as append stops
>>> working as I
>>> have no columns any more I'd really appreciate some help on
>>> this thx
>>>
>>>
>>>
>>> --
>>>
>>>
>>> .~. In my life God comes first....
>>> /V\ but Linux is pretty high after that :-D
>>> /( )\ Francis (Grizzly) Smit
>>> ^^-^^ http://www.smit.id.au/
>>>
>>> _______________________________________________
>>> gtkmm-list mailing list
>>> [email protected] <mailto:[email protected]>
>>> https://mail.gnome.org/mailman/listinfo/gtkmm-list
>>>
>>>
>>>
>>>
>>> --
>>> Atentamente:
>>> Juan Ángel Moreno Fernández
>>> [email protected] <mailto:[email protected]>
>>> ------------------------------
>>> Proyecto Gelide
>>> http://gelide.sf.net
>>> ------------------------------
>>
>> --
>>
>>
>> .~. In my life God comes first....
>> /V\ but Linux is pretty high after that :-D
>> /( )\ Francis (Grizzly) Smit
>> ^^-^^ http://www.smit.id.au/
>>
>>
>> _______________________________________________
>> gtkmm-list mailing list
>> [email protected] <mailto:[email protected]>
>> https://mail.gnome.org/mailman/listinfo/gtkmm-list
>>
>>
>>
>>
>> --
>> Atentamente:
>> Juan Ángel Moreno Fernández
>> [email protected] <mailto:[email protected]>
>> ------------------------------
>> Proyecto Gelide
>> http://gelide.sf.net
>> ------------------------------
>>
>>
>>
>> --
>> Atentamente:
>> Juan Ángel Moreno Fernández
>> [email protected] <mailto:[email protected]>
>> ------------------------------
>> Proyecto Gelide
>> http://gelide.sf.net
>> ------------------------------
>>
>>
>> _______________________________________________
>> gtkmm-list mailing list
>> [email protected]
>> https://mail.gnome.org/mailman/listinfo/gtkmm-list
>
--
.~. In my life God comes first....
/V\ but Linux is pretty high after that :-D
/( )\ Francis (Grizzly) Smit
^^-^^ http://www.smit.id.au/
_______________________________________________
gtkmm-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list