[Gtk-sharp-list] Filling a Gtk.TreeView with a Parent-Child object
Christian Hoff
christian_hoff at gmx.net
Sat Jan 3 05:55:47 EST 2009
Aphelion wrote:
> Hi everyone,
>
> I am a C# Developer orienting Mono. To do this, i am writing a little
> outliner application to get to know GTK#.
>
> Currently i am experiencing difficulties with the Gtk.TreeView. What i want
> to achieve: I have an object called TaskEntry. This taskEntry contains
> properties like a Description and a DueDate. It also has a
> TaskEntryCollection containing Child Tasks.
>
> I just cant find the right way to load my TaskEntry objects recursively to
> the TreeView.
>
> My current approach is the code below. However; it will not commit changes
> to my objects this way. Can anyone help me into the right direction for
> solving this problem?
>
How does you program behave using that code?
For an introduction to TreeModels, read:
http://www.mono-project.com/GtkSharp_TreeView_Tutorial
A custom tree model could be a better approach here especially if you
want to have your model editable and keep the edited data in sync with
your objects:
http://www.mono-project.com/ImplementingGInterfaces
The examples in the Gtk# SVN repo are always worth looking at, too.
> protected void FillTreeView()
> {
> // Loop through the tasks and add them to the store
> foreach(TaskEntry task in _rootTaskEntry.Children)
> {
> Gtk.TreeIter taskIter = _outlineTreeStore.AppendValues(task);
> FillTreeView(taskIter, task);
> }
> }
>
> protected void FillTreeView(TreeIter taskIter, TaskEntry task)
> {
> foreach(TaskEntry childTask in task.Children)
> {
> TreeIter newIter = _outlineTreeStore.AppendValues(taskIter, childTask);
> FillTreeView(newIter, childTask);
> }
> }
>
>
More information about the Gtk-sharp-list
mailing list