2010-03-16 2 views
4

F #을 통해 Gtk # 위젯을 사용하여 디렉토리 구조를 표시하고 싶지만 TreeView를 F #으로 변환하는 방법을 파악하는 데 어려움을 겪고 있습니다. 나는 F #을 사용는 GTK # 위젯이 트리 구조를 보여 얼마나F #을 사용하여 다중 레벨 TreeView를 만드는 방법은 무엇입니까?

Directory1 
    SubDirectory1 
    SubDirectory2 
    SubSubDirectory1 
    SubDirectory3 
Directory2 

:이처럼 보이는 디렉토리 구조를 가지고 말?

편집 :

gradbot의 내가 몇 가지 예외와 기대했다 대답했다. ListStore를 사용하는 경우 대신 다음을 사용하면 수준을 확장 할 수 있습니다.

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

확장 레벨을 가진 레이아웃을 얻을 수 있습니다. 열이 명시 적으로 배열로 전달되는 것을

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

참고 : 사용하는 방법을 오버로드 알아낼 컴파일러에 대한 몇 가지 단서를 추가 할 수 있도록 이렇게 그러나 AppendValues에 전화를 나누기.

마지막으로, 당신은 할 수 둥지 수준은 더욱 추가]에 의해 반환 된 ListIter를 사용하여

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 
+0

일에, 값 iter을 값을 추가하는 것입니다 생각합니다. 그것은 당신의 위키입니다. :) – gradbot

답변

5

난 당신이 무엇을 찾고 있는지 정확히 모르겠어요 값 여기서는 해 tutorials에서 번역 된 예이다. 시작하는 데 도움이 될 수 있습니다. tutorial site에서 가져온 이미지입니다.

alt text http://www.mono-project.com/files/9/92/GtkSharpTreeViewTutorial-Tree1.png
나는 다단계 트리보기에 키가 대답 질문을 편집,이 라인 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()