Following the suggestions I modified the code as follows:
This is the function called when I click the Add item button, basically passing the selected item and the data to add
Code: Select all
void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event))
{
wxDataViewItem selectedItem = m_ctrl->GetSelection();
m_music_model->Add("add this", "add that", selectedItem);
}
And here below the DVM function that should perform the operation:
Code: Select all
void MyTreeCrownModel::Add(const wxString &crownLayerType, const wxString &crownLayerName, const wxDataViewItem &item)
{
MyTreeCrownModelNode *node = (MyTreeCrownModelNode*)item.GetID();
wxLogMessage("selected item ID: %s", node->m_crownLayerID); // check the selected item ID, which is OK
MyTreeCrownModelNode *m_addThis = new MyTreeCrownModelNode(m_root, crownLayerType, crownLayerName);
m_root->Append(m_addThis); // add the new item to the root
wxDataViewItem child((void*)m_addThis);
wxDataViewItem parent((void*)node);
ItemAdded(parent, child); // parent it to the selected item
}
Still not working, I honestly can't see what's the issue. From the documentation and sample I can't figure out either if the Append has to reference the item, or the root (as in the example above) but it doesn't really matter as the item doesn't get added.
ItemAdded returns a false.