[Gtk-sharp-list] Data-Bound TreeView
Jacek Ruzyczka
ruzyczka at versanet.de
Sat Jan 5 11:06:54 EST 2008
Hi folks,
for the ongoing effort to develop data-bound Gtk# objects, I have some remark
when it comes to data-binding a TreeView:
When storing a tree data structure in an RDBMS, you would normally define a
table like this:
CREATE TABLE treestore (
id INTEGER NOT NULL PRIMARY KEY,
super_id INTEGER REFERENCES treestore (id) ON DELETE CASCADE,
name VARCHAR (35)
);
This means: A line in this table, which has super_id = NULL, represents a root
node, otherwise it would represent a "branch" (if some other line points at
it with its super_id entry), or a "leaf" (otherwise).
When pouring such data into the TreeView, you start with root nore #1, then
with the first child node of root node #1, and so on...recursively. Once you
have added all leafs, you would return to the level just above it (a node can
have more than one child) and at last to the root level to continue with root
#2, if it exists:
+ root_1
+- branch_11
|+- leaf_111
|+- leaf_112
+- branch_12
|+- leaf_121
+ root_2
[...]
Nowadays, you use the TreeView, associate a TreeStore with it as a model, and
then recursively call the AppendValues() method on the TreeStore, using the
TreeIter object returned by this method. The two big challenges I have
expected so far are:
*) The result set must come pre-sorted from the RDBMS (in the manner stated
above), otherwise my C# app would have to scan through the result set, which
consumes a lot of client-side computing time. Pre-sorting is easy with two
hierarchy levels (root, leaf), but with three or four levels, you have to
rely on stored procedures on RDBMS side, which are normally NOT portable.
*) The TreeIters of all objects have to be stored in a collection and, when
some node gets a child node, retrieved.
Shall those of you who are now involved in coding the data-bound Gtk# widgets
use this as a starting point. Comments and questions are, of course, always
welcome.
Regards
Jacek Rużyczka
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20080105/fa4de302/attachment.bin
More information about the Gtk-sharp-list
mailing list