[Java-gnome-developer] DataColumns and adding TreeView rows
Brought to you by:
afcowie
From: Spyros S. <fou...@gm...> - 2005-10-27 12:59:06
|
Well, this may sound a little bit silly, however I have a little problem when it comes to adding a row. I do not know what to put as DataColumn in the setValue method. But let's take a look to the following piece of code: public class Whatever{ TreeView list; public Whatever(){ initTree(); ... ... fillTree(); } /*Initialize the tree by creating the columns, but NOT filling in the Data*= / private void initTree(){ list =3D (TreeView)glade.getWidget("listTreeView"); DataColumn[] dc =3D new DataColumn[4]; for(int i =3D 0; i < 4; i++) dc[i] =3D new DataColumnString(); ListStore ls =3D new ListStore(dc); tv.setModel(ls); TreeViewColumn col0 =3D new TreeViewColumn(); col0.setTitle("ONE"); CellRendererText render0 =3D new CellRendererText(); col0.setResizable(true); col0.packStart(render0, false); col0.addAttributeMapping(render0, org.gnu.gtk.CellRendererText.Attribute.TEXT , (DataColumnString)dc[0]); TreeViewColumn col1 =3D new TreeViewColumn(); col1.setTitle("TWO"); CellRendererText render1 =3D new CellRendererText(); col1.setResizable(true); col1.packStart(render1, false); col1.addAttributeMapping(render1, CellRendererText.Attribute.TEXT, (DataColumnString)dc[1]); TreeViewColumn col2 =3D new TreeViewColumn(); col2.setTitle("THREE"); CellRendererText render2 =3D new CellRendererText(); col2.setResizable(true); col2.packStart(render2, false); col2.addAttributeMapping(render2, CellRendererText.Attribute.TEXT, (DataColumnString)dc[2]); TreeViewColumn col3 =3D new TreeViewColumn(); col3.setTitle("FOUR"); CellRendererText render3 =3D new CellRendererText(); col3.setResizable(true); col3.packStart(render3, false); col3.addAttributeMapping(render3, CellRendererText.Attribute.TEXT, (DataColumnString)dc[3]); tv.appendColumn(col0); tv.appendColumn(col1); tv.appendColumn(col2); tv.appendColumn(col3); /* No further data is provided to the TreeView*/ } } private void fillTree(){ ListStore ls =3D (ListStore)(list.getModel()); TreeIter it =3D ls.appendRow(); ls.setValue(it, /*WHAT HERE???*/, "Test"); } } Well I was not able to find a way to get the DataColumn from the Model, as = I would when calling method ls.setValue(it, (DataColumnString)dc[0], "A String"); from within the method initTree. I mean, there is no dc to use in method fillTree(). I've read in the docs that this should be done through the Renderer, however I wasn't able to find a solution to this either. Is there a way to retrieve the DataColumn of the specified ListStore? /** * Sets a value in the data store. To display the data in the widget, you * need to associate the datablock with the renderer, using methods of the * {@link TreeViewColumn}. * @param iter A valid iterator which specifies the row in which the data * should be set. Iterators can be gained by using methods such as * {@link #appendRow()}. * @param dataBlock The data block to store the value in. * @param value The value to store. This must be of the same type * for the column as that set in the constructor to the ListStore. */ public void setValue( TreeIter iter, DataColumnString dataBlock, String value){...} Thnx everyone that might take a look in advance, Spyros "Foucault" Stathopoulos |