[Gambas-user] How to search for an item in a treeview

M0E Lnx m0e.lnx at ...626...
Fri Mar 28 21:43:55 CET 2008


Mission accomplished!

I managed to do it from the array the way I planned it...
The main problem was getting around the double parent entires

but that can be solved by adding yet another array and analyzing each
parent.. then check for it's existance, and if false, then add it

treeview = great object.



On Fri, Mar 28, 2008 at 12:20 PM, M0E Lnx <m0e.lnx at ...626...> wrote:
> I have managed to get the results from the search within the array
> I did this by adding a line of code that stores each entry as it is
> thrown into the treeview for the first time
>
> I can retreive results by doing something like this
>
> PUBLIC SUB RUN_SEARCH(sQuery as string)
>
> DIM sListarr as string[]
> DIM i as Integer
> DIM sItem as string
> DIM sResults as string
>
> sListarr = SPLIT(sRawList, "@") ' sRawList is the massive string that
> contains the treeview's entries separated by a "@"
> FOR i = 0 to sListArr.Count - 1
> sItem = sListarr[i]
> IF Instr(sItem, sQuery, 1, gb.case) > 0 then
> sResults = sResults & sItem & gb.newline ' will separate these by new lines
> END IF
> NEXT
> END
>
> This produces a string variable filled with hits from the search.
> These hits are formatted like this
> <parent>!<item>
> <parent>!<item>
> That is how they get added to the massive list in the first place
>
> So now, out of that list, I need to create entries on the treeview
> And of course this is where I'm running into trouble
>
> A hit can be found on more than one parent
> in which case, I need to add each parent (without double entries)
> and populate each parent with whatever is after the "!"
>
> Please help :(
>
>
>
>
> On Fri, Mar 28, 2008 at 8:23 AM, M0E Lnx <m0e.lnx at ...626...> wrote:
> > mmm.. I'm not sure what's what I want to do..
> >
> > I've done this before using a listview.. but the listview component I
> > can understand more easily the problem is that it doesn't offer
> > collapsable parent entries.
> >
> > that's why I'd rather wipe out the treeview, and repopulate it.
> >
> >
> >
> >
> > On 3/28/08, Robert Rowe <robert.c.rowe at ...626...> wrote:
> > > Why don't you add a second treeview that is initially hidden. As you
> > >  find your results add them to the hidden treeview. When the search
> > >  completes, show the hidden treeview and hide the original one.
> > >
> > >
> > >  Robert Rowe
> > >
> > >
> > >  M0E Lnx wrote:
> > >  > Sorry for not being too specifc.
> > >  >
> > >  > I'm trying to allow the user to search for specific items (initially
> > >  > listed in the treeview)
> > >  >
> > >  > so First, I want to populate the treeview with a massive collection
> > >  > (already done)
> > >  > Need to offer a search feature (this needs to find stuff in the
> > >  > treeview (you already did))
> > >  > Need to display ONLY the results of the search in the treeview.
> > >  >
> > >  > There will be a button that the user can hit to restore the treeview
> > >  > to the original content (full list)
> > >  >
> > >  >
> > >  >
> > >  > On 3/27/08, Stephen Bungay <sbungay at ...981...> wrote:
> > >  >
> > >  >>    Yes, your original post did not ask for anything to be repopulated..
> > >  >>  indeed, nothing has been removed from the treeview so you don;t have to
> > >  >>  repopulate it using this method.
> > >  >>    Could you be a little more clear on what it is you are trying to
> > >  >>  accomplish? We have the find done.. whats with the repopulate?
> > >  >>
> > >  >>
> > >  >>  M0E Lnx wrote:
> > >  >>  > OK... I can see how that will find the hits... but I dont see how it
> > >  >>  > will re-populate it using only the items that were found.
> > >  >>  >
> > >  >>  > I guess I must have misphrased that in the first place
> > >  >>  >
> > >  >>  >
> > >  >>  > On 3/26/08, Stephen Bungay <sbungay at ...981...> wrote:
> > >  >>  >>    Ok try this. It is based on a save routine that I used in an
> > >  >>  >>  edutainment application I developed about a year ago... I pulled my hair
> > >  >>  >>  out trying to come up with a good recursive routine to do walk the tree,
> > >  >>  >>  and failed miserably at it. This treeview did not lend itself well to a
> > >  >>  >>  recursive walk through... but there is another SIMPLER way, Benoit
> > >  >>  >>  pointed me in the right direction (Thanks Benoit), and now lets pay it
> > >  >>  >>  forward.
> > >  >>  >>
> > >  >>  >>  Create a test project with three controls on it. Don't rename the
> > >  >>  >>  controls, just use the default names. The controls to put on FMAIN are a
> > >  >>  >>  button, a treeview and a TextArea.
> > >  >>  >>    Now copy and paste this code into FMain
> > >  >>  >>
> > >  >>  >>  PUBLIC Y AS String
> > >  >>  >>
> > >  >>  >>  PUBLIC SUB Form_Open()
> > >  >>  >>
> > >  >>  >>    WITH TreeView1
> > >  >>  >>         .Add("A", "Item A")
> > >  >>  >>         .Add("A1", "Item A1",, "A")
> > >  >>  >>         .Add("B", "Item B")
> > >  >>  >>         .Add("B1", "Item B1",, "B")
> > >  >>  >>         .Add("B1.1", "Item B1.1",, "B1")
> > >  >>  >>         .Add("C", "Item C")
> > >  >>  >>         .Add("D", "Item D")
> > >  >>  >>         .Add("D1", "Item D1",, "D")
> > >  >>  >>         .Add("E", "Item E")
> > >  >>  >>    END WITH
> > >  >>  >>
> > >  >>  >>  END
> > >  >>  >>
> > >  >>  >>  PUBLIC SUB Button1_Click()
> > >  >>  >>    WalkTree(TreeView1)
> > >  >>  >>  END
> > >  >>  >>
> > >  >>  >>
> > >  >>  >>  PRIVATE SUB WalkTree(pTreeView AS TreeView)
> > >  >>  >>    DIM sText AS String
> > >  >>  >>
> > >  >>  >>    pTreeView.MoveFirst()
> > >  >>  >>
> > >  >>  >>    REPEAT
> > >  >>  >>       sText = sText & pTreeView.Item.Key & ", " & "'" &
> > >  >>  >>  pTreeView.Item.Text & "'" & "\n"
> > >  >>  >>       pTreeView.Item.Expanded = TRUE
> > >  >>  >>    UNTIL pTreeView.MoveBelow()
> > >  >>  >>
> > >  >>  >>    TextArea1.Text = sText
> > >  >>  >>
> > >  >>  >>  END
> > >  >>  >>
> > >  >>  >>
> > >  >>  >>    When you push the button it will iterate down through the tree and
> > >  >>  >>  push the text of each node (and it's key) to a string, After the tree
> > >  >>  >>  has been 'walked' the string will be dumped to the Text area.
> > >  >>  >>    Use this to do a search on each ode as you come to it.
> > >  >>  >>    Job done.
> > >  >>  >>
> > >  >>  >>  Steve.
> > >  >>  >>
> > >  >>  >>
> > >  >>  >>  M0E Lnx wrote:
> > >  >>  >>  > I have a treeview populated with lots of entries... I'm trying to
> > >  >>  >>  > provide a function that would search within the contents of that
> > >  >>  >>  > treeview for a specific string.
> > >  >>  >>  > Can anyone think of a way to do that?
> > >  >>  >>  >
> > >  >>  >>  > I've been trying the FIND method in the treeview, but it's quite
> > >  >>  >>  > different from other find methods...
> > >  >>  >>  >
> > >  >>  >>
> > >  >>  >>> -------------------------------------------------------------------------
> > >  >>  >>  > Check out the new SourceForge.net Marketplace.
> > >  >>  >>  > It's the best place to buy or sell services for
> > >  >>  >>  > just about anything Open Source.
> > >  >>  >>  > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> > >  >>  >>  > _______________________________________________
> > >  >>  >>  > Gambas-user mailing list
> > >  >>  >>  > Gambas-user at lists.sourceforge.net
> > >  >>  >>  > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >  >>  >>  >
> > >  >>  >>
> > >  >>  >>
> > >  >>  >>  -------------------------------------------------------------------------
> > >  >>  >>  Check out the new SourceForge.net Marketplace.
> > >  >>  >>  It's the best place to buy or sell services for
> > >  >>  >>  just about anything Open Source.
> > >  >>  >>  http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> > >  >>  >>  _______________________________________________
> > >  >>  >>  Gambas-user mailing list
> > >  >>  >>  Gambas-user at lists.sourceforge.net
> > >  >>  >>  https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >  >>  >>
> > >  >>  >
> > >  >>  > -------------------------------------------------------------------------
> > >  >>  > Check out the new SourceForge.net Marketplace.
> > >  >>  > It's the best place to buy or sell services for
> > >  >>  > just about anything Open Source.
> > >  >>  > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> > >  >>  > _______________________________________________
> > >  >>  > Gambas-user mailing list
> > >  >>  > Gambas-user at lists.sourceforge.net
> > >  >>  > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >  >>  >
> > >  >>
> > >  >>
> > >  >>  -------------------------------------------------------------------------
> > >  >>  Check out the new SourceForge.net Marketplace.
> > >  >>  It's the best place to buy or sell services for
> > >  >>  just about anything Open Source.
> > >  >>  http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> > >  >>  _______________________________________________
> > >  >>  Gambas-user mailing list
> > >  >>  Gambas-user at lists.sourceforge.net
> > >  >>  https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >  >>
> > >  >>
> > >  >
> > >  > -------------------------------------------------------------------------
> > >  > Check out the new SourceForge.net Marketplace.
> > >  > It's the best place to buy or sell services for
> > >  > just about anything Open Source.
> > >  > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> > >  > _______________________________________________
> > >  > Gambas-user mailing list
> > >  > Gambas-user at lists.sourceforge.net
> > >  > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >  >
> > >  >
> > >
> > >  -------------------------------------------------------------------------
> > >  Check out the new SourceForge.net Marketplace.
> > >  It's the best place to buy or sell services for
> > >  just about anything Open Source.
> > >  http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> > >  _______________________________________________
> > >  Gambas-user mailing list
> > >  Gambas-user at lists.sourceforge.net
> > >  https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >
> >
>




More information about the User mailing list