[Gambas-user] Populating a tree view from code ... Please help

M0E Lnx m0e.lnx at ...626...
Tue Mar 25 20:33:34 CET 2008


I'm trying to populate a treeview object with code, but I'm having a
hard time getting the desired results.

The tree view should contain the contents of a directory on the system
Here is what my code looks like

PUBLIC SUB LOAD_ALL_REPOS()

DIM sDirPic AS Picture
DIM sPortPic AS Picture

DIM sRepList AS String
DIM sRepoarr AS String[]
DIM sPortList AS String
DIM sPortArr AS String[]
DIM sRepo AS String
DIM sPort AS String
DIM i AS Integer
DIM ii AS Integer


sDirPic = Picture["Icons/nuoveXT-1.6/16x16/gtk/gtk-open.png"]
sPortpic = Picture["Icons/nuoveXT-1.6/16x16/gtk/gtk-dnd.png"]

SHELL "ls -m /usr/ports " TO sRepList
sRepList = Trim(sRepList) ' Trim out excess spaces

sRepoarr = Split(sRepList, ",")

FOR i = 0 TO sRepoarr.count - 1
  sRepo = Trim(Left(sRepoarr[i], InStr(sRepoarr[i], "/")))
  frmPorts.tvPorts.Add(sRepoarr[i], sRepo, sDirPic) ' Add the repo to the list

    SHELL "ls -m /usr/ports" &/ sRepoarr[i] TO sPortList
        sPortArr = Split(sPortList, ",")
          FOR ii = 0 TO sPortArr.Count - 1
            sPort = Trim(sPortArr[ii])
            FrmPorts.tvPorts.Add(sPort & i & ii, sPort, sPortPic,
sRepo) ' The the port
          NEXT

NEXT
END

I get the first entry right... It adds a Parent, then it adds all the
other (child) objects inside that parent... that's how it's supposed
to work
But on the rest of the entries, instead of getting each parent's child
objects, I get a list of all the parent objects...

Can someone point out where the problem is, or suggest a better way of
doing this?
I tried rDir, but seems harder to control the output in this case, so
I thought I'd try some arrays

Thanks




More information about the User mailing list