How to create a layered TreeView using F #?

I would like to display the directory structure using the Gtk # widget via F #, but it’s hard for me to figure out how to translate TreeViews into F #. Let's say I had a directory structure that looked like this:

Directory1 SubDirectory1 SubDirectory2 SubSubDirectory1 SubDirectory3 Directory2 

How to show this tree structure using Gtk # widgets using F #?

EDIT:

gradbot was the answer I was hoping for with a few exceptions. If you use ListStore, you lose the ability to expand levels if you use instead:

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

you get a layout with extensible levels. However, this interrupts the calls to AppendValues, so you need to add some compiler hints 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 level the levels even further using the ListIter returned by the 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 
+4
source share
1 answer

I'm not quite sure what you are looking for, but here is a translated example from their textbooks . It can help you get started. Image taken from training site .

alt text
I think the key to the multi-level tree view is adding values ​​to the values, iter in this line musicListStore.AppendValues(iter, "Fannypack", "Nu Nu (Yeah Yeah) (double j and haze radio edit)") |> ignore

 // you will need to add these references gtk-sharp, gtk-sharp, glib-sharp // and set the projects running directory to // C:\Program Files (x86)\GtkSharp\2.12\bin\ module SOQuestion open Gtk open System let main() = Gtk.Application.Init() // Create a Window let window = new Gtk.Window("TreeView Example") window.SetSizeRequest(500, 200) // Create our TreeView let tree = new Gtk.TreeView() // Add our tree to the window window.Add(tree) // Create a column for the artist name let artistColumn = new Gtk.TreeViewColumn() artistColumn.Title <- "Artist" // Create the text cell that will display the artist name let artistNameCell = new Gtk.CellRendererText() // Add the cell to the column artistColumn.PackStart(artistNameCell, true) // Create a column for the song title let songColumn = new Gtk.TreeViewColumn() songColumn.Title <- "Song Title" // Do the same for the song title column let songTitleCell = new Gtk.CellRendererText() songColumn.PackStart(songTitleCell, true) // Add the columns to the TreeView tree.AppendColumn(artistColumn) |> ignore tree.AppendColumn(songColumn) |> ignore // Tell the Cell Renderers which items in the model to display artistColumn.AddAttribute(artistNameCell, "text", 0) songColumn.AddAttribute(songTitleCell, "text", 1) let musicListStore = new Gtk.ListStore([|typeof<String>; typeof<String>|]) let iter = musicListStore.AppendValues ("Dance") musicListStore.AppendValues (iter, "Fannypack", "Nu Nu (Yeah Yeah) (double j and haze radio edit)") |> ignore let iter = musicListStore.AppendValues ("Hip-hop") musicListStore.AppendValues (iter, "Nelly", "Country Grammer") |> ignore // Assign the model to the TreeView tree.Model <- musicListStore // Show the window and everything on it window.ShowAll() // add event handler so Gtk will exit window.DeleteEvent.Add(fun _ -> Gtk.Application.Quit()) Gtk.Application.Run() [<STAThread>] main() 
+5
source

Source: https://habr.com/ru/post/1304222/


All Articles