How do I create a multi-level TreeView using F#?

Posted by TwentyMiles on Stack Overflow See other posts from Stack Overflow or by TwentyMiles
Published on 2010-03-16T03:22:54Z Indexed on 2010/03/16 5:36 UTC
Read the original article Hit count: 460

Filed under:
|
|
|

I would like to display a directory structure using Gtk# widgets through F#, but I'm having a hard time figuring out how to translate TreeViews into F#. Say I had a directory structure that looks like this:

Directory1
  SubDirectory1
  SubDirectory2
    SubSubDirectory1
  SubDirectory3
Directory2

How would I show this tree structure with Gtk# widgets using F#?

EDIT:

gradbot's was the answer I was hoping for with a couple of exceptions. If you use ListStore, you loose the ability to expand levels, if you instead use :

let musicListStore = new Gtk.TreeStore([|typeof<String>; typeof<String>|])

you get a layout with expandable levels. Doing this, however, breaks the calls to AppendValues so you have to add some clues for the compiler to figure out which overloaded method to use:

musicListStore.AppendValues (iter, [|"Fannypack" ; "Nu Nu (Yeah Yeah) (double j and haze radio edit)"|])

Note that the columns are explicitly passed as an array.

Finally, you can nest levels even further by using the ListIter returned by Append Values

let iter = musicListStore.AppendValues ("Dance")
let subiter = musicListStore.AppendValues (iter, [|"Fannypack" ; "Nu Nu (Yeah Yeah) (double j and haze radio edit)"|])
musicListStore.AppendValues (subiter, [|"Some Dude"; "Some Song"|]) |> ignore

© Stack Overflow or respective owner

Related posts about F#

Related posts about gtk#