void removeButton_Clicked(object sender, EventArgs e)
{
//get selected iter and the replacement selection
TreeIter iter, newSelection;
TreeModel model;
if (!itemTree.Selection.GetSelected (out model, out iter))
return;
newSelection = iter.Copy ();
if (!IterPrev (model, ref newSelection)) {
newSelection = iter.Copy ();
if (!itemStore.IterNext (ref newSelection))
newSelection = TreeIter.Zero;
}
//new selection. Zeroing previousIter prevents trying to update name of deleted iter.
previousIter = TreeIter.Zero;
if (itemStore.IterIsValid (newSelection))
itemTree.Selection.SelectIter (newSelection);
//and the removal and index update
((ListStore) model).Remove (ref iter);
UpdateIndices ();
}