Message-ID: <4219AE78.4080505 at tin.it> Date: Mon, 21 Feb 2005 10:48:40 +0100 From: Stalkern 2 MIME-Version: 1.0 To: Ethan Aubin CC: lablgtk at kaba.or.jp Subject: Re: tree view models written in ocaml References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Ethan Aubin wrote: > Hi, I'm trying to figure out Tree Views but I'm running into some > problems. I've a few objects/records written in ocaml I'd like to use > as the model of the tree view, but I'm missing how to setup the column > views, so that they pull and format (I can convert what I need into > text) the right fields. > > Could someone post (or point me towards) an example of how to do this? > E.g. Maybe take the tree view working example at > http://compiler.kaist.ac.kr/~shoh/ocaml/lablgtk2/treeview-tutorial/ch05s06.html > and use the types > > type gender = Male | Female > type person = {name : string; gender : gender; age : int} > > instead of the 3 distinct columns? Any help is appreciated! - Ethan > > You won't use your own data type as the model, you'll set the model and then fill it with the data using iters and columns as a kind of X,Y coords. That's why you are supposed to use three columns and feed them with person.name, person.gender and person.age. If you may be interested in it, I've recently updated my online example of fileviewer at http://www.connettivo.net/article.php3?id_article=61 Concerning your example: you can write the to_string and of_string converters of your type yourself, then use a GTree.cell_renderer_text; reject the changes in a gender cell if gender is not letter M or F, for instance. For renderer, you can also use the GTree.cell_renderer_toggle. To set some rows to be non-editable, you can use a hidden column holding some is_editable information. Hope it helps Ernesto