Re: [Java-gnome-developer] [TreeView] How to know which DataColumn is used by a TreeViewColumn ?
Brought to you by:
afcowie
From: Andrew C. <an...@op...> - 2006-06-06 06:56:43
|
On Mon, 2006-06-05 at 17:32 +0200, Mehdi Rabah wrote: > I'm trying to get the value of a cell after a double-click ^^^^^^^^^^^^^^^^^^^ For an activate, you just ask the event for the TreeIter that goes with it. We do something like this: view.addListener(new TreeViewListener() { public void treeViewEvent(TreeViewEvent event) { if (event.getType() == TreeViewEvent.Type.ROW_ACTIVATED) { TreeIter pointer = event.getTreeIter(); Blah b = (Blah) model.getValue(pointer, blahObject_DataColumn); /* do something with b */ } } }); To see this in context, refer to [1]. > But to get a value with the ListStore.getValue() I also need the > DataColumn behind the TreeViewColumn, and I don't know how to get it. The bad way to do it is to get ask the TreeViewEvent for the TreeModel and ask the TreeModel for the DataColumn[], and then for the 5th DataColumn, say dataColArry[4] or whatever. A much better way to do it is to have a field for each DataColumn as private members of your class. Then you've got all the DataColumns available by name, and you just use them. As with all of UI programming, variable naming pretty quickly becomes a problem. If you look at lines 61-119 of the above source file (or follow [2]), you'll see how we handle it. Oh - if for whatever reason TreeView{Listener,Event} isn't what you want, then see also TreeSelection{Listener,Event} AfC Sydney [1]: http://research.operationaldynamics.com/source/darcsweb/?r=objective;a=headblob;f=/src/accounts/ui/TransactionListView.java#l258 [2]: http://research.operationaldynamics.com/source/darcsweb/?r=objective;a=headblob;f=/src/accounts/ui/TransactionListView.java#l56 -- Andrew Frederick Cowie Technology strategy, managing change, establishing procedures, and executing successful upgrades to mission critical business infrastructure. http://www.operationaldynamics.com/ Sydney New York Toronto London |