[wxPython] Searching Data from List Control

Hi,

On a similar context, I would like to search on a partial string on a
'listbox' and find the
position of the 1st matching string.

I used 'wxListBox.FindString('matchingstring') but it always returns -1 as
position.

          lst = wxListBox(panel, ID_BOX_LIST1,
                           wxPoint(20,70), wxSize(400,500),
                           ListData, wxLB_SINGLE | wxLB_HSCROLL)

     searchresult=self.lst.FindString('ThisStringExistInTheListData')

Am I doing anything wrong !
How should this be constracted ?

Thanks.
Syed A. Nabi
snabi@visteon.com <mailto:snabi@visteon.com>

:>-----Original Message-----
:>From: Brendan J Simon [mailto:brendan.simon@ctam.com.au]
:>Sent: Wednesday, November 15, 2000 5:49 PM
:>To: wxpython-users@lists.sourceforge.net
:>Subject: Re: [wxPython] Reading Data from List Control
:>
:>
:>Ruben Marquez wrote:
:>
:>> I have a list control with three columns. I would
:>> like to be able to read the information on any given
:>> column of the selected item. However, the GetItemText
:>> method only accepts two parameters (self, and the Item
:>> index). This only gives me the text of the first
:>> column. How can one read the text of the other
:>> columns? Will appreciate any help.
:>
:>I asked the same question about 2 weeks ago, and I didn't get a
:>response. I was mainly interested in sorting the list based on which
:>column was clicked. I had to maintain a seperate 2 dimensional list,
:>sort it appropriately, and then place the data back into the
:>listCtrl.
:>It would be nice if the C++ wxListCtrl had a method to sort
:>based on a
:>column. It would also be very beneficial to be able to read any
:>row/column data.
:>
:>Brendan Simon.
:>
:>_______________________________________________
:>wxPython-users mailing list
:>wxPython-users@lists.sourceforge.net
:>http://lists.sourceforge.net/mailman/listinfo/wxpython-users
:>

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Hi,

On a similar context, I would like to search on a partial string on a
'listbox' and find the
position of the 1st matching string.

Something like this maybe? (It was added to the demo a couple days ago, and
hasn't been tested much yet.)

class wxFindPrefixListBox(wxListBox):
    def __init__(self, parent, id, pos=wxDefaultPosition,
size=wxDefaultSize,
                 choices=[], style=0, validator=wxDefaultValidator):
        wxListBox.__init__(self, parent, id, pos, size, choices, style,
validator)
        self.typedText = ''
        EVT_KEY_UP(self, self.OnKey)

    def FindPrefix(self, prefix):
        if prefix:
            prefix = string.lower(prefix)
            length = len(prefix)
            for x in range(self.Number()):
                text = self.GetString(x)
                text = string.lower(text)
                if text[:length] == prefix:
                    return x
        return -1

    def OnKey(self, evt):
        key = evt.GetKeyCode()
        if key >= 32 and key <= 127:
            self.typedText = self.typedText + chr(key)
            item = self.FindPrefix(self.typedText)
            if item != -1:
                self.SetSelection(item)

        elif key == WXK_BACK: # backspace removes one character and backs
up
            self.typedText = self.typedText[:-1]
            if not self.typedText:
                self.SetSelection(0)
            else:
                item = self.FindPrefix(self.typedText)
                if item != -1:
                    self.SetSelection(item)

        else:
            evt.Skip()

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxPython.org Java give you jitters?
http://wxPROs.com Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users