treectrl - getselection

I am not sure about your specific problem, but I am doing the same kind of
thing, but the tree has the multiple selection style turned on. When I do,
GetSelections()[0], which accesses the first item in the selection array, if
nothing is selected i get an exception. Dont know if this helped at all, but
good luck.

Gilad

···

----- Original Message -----
From: "Chris Mahoney" <built4living@excite.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Thursday, November 06, 2003 12:13 PM
Subject: [wxPython-users] treectrl - getselection

Hi,

This is the first time I have felt the need to post to this list, but I

have always found it a valuable resource. Thanks to all who contribute.

I have this function to add a branch to a treectrl at the selected item.

I want it to raise an exception if nothing is selected, rather than just
failing silently. However, the exception is only raised if the treectrl is
completely empty. As soon as a root is added to the treectrl the exception
isn't raised even when nothing is selected.

************************************
def addBranch(self, event):

    try:
        selection = self.treectrl1.GetSelection()
        branchNum = self.treectrl1.GetChildrenCount(selection, recursively

= False)

        newBranch = self.treectrl1.AppendItem(selection, ("Branch %i" %

branchNum))

        self.treectrl1.SetItemImage(newBranch, newBranchClose,

wxTreeItemIcon_Normal)

        self.treectrl1.SetItemImage(newBranch, newBranchOpen,

wxTreeItemIcon_Expanded)

        event.Skip()

    except:
        dlg = wxMessageDialog(self, "Cannot add branch without

selection!", "Selection Error", style=wxOK | wxICON_ERROR)

        dlg.CenterOnScreen(wxBOTH)
        try:
            if dlg.ShowModal() == wxID_OK:
                event.Skip()
            finally: dlg.Destroy()
************************************

What am I missing? According to the documentation,

"wxTreeCtrl::GetSelection...Returns the selection, or an invalid item if
there is no selection." Shouldn't this be enough to raise the exception?

TIA,
Chris

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org