set parents in treetable

Hi:

I have a question regarding treetables…I’m using the following code to set the parents of the treetable items and it doesn’t work…any ideas?..

public TreeTable prueba = new TreeTable();

...

prueba.addContainerProperty("Name", String.class, "");
prueba.addContainerProperty("Father", String.class, "");

for (int i = 0; i < contenedorUsers.size(); i++) {

Object id = contenedorUsers.getIdByIndex(i);
Item item = contenedorUsers.getItem(id); 
			
prueba.addItem(new Object[] {item.getItemProperty("Name").getValue().toString(),
				item.getItemProperty("Father").getValue().toString()},null);
}

After this, I get a treetable with two columns, one with the name and one for the father’s name…after that, I do:

for (int i=1; i<=prueba.size();i++){
			
	Object name = prueba.getItem(i).getItemProperty("Name");
	Object father = prueba.getItem(i).getItemProperty("Father");
	prueba.setParent(name, father);
	prueba.setCollapsed(name, false);

		}

After this, nothing happens, and I only have the table with two columns but with no hiearchy on it…if I do this item by item (they are not too many yet)…I get a perfectly goo treetable…

Any idea on why is this failing???..thanks!!!

setParent(child, parent) works with item id’s. You seem to be using integers as item id’s. This is because your line:

prueba.addItem(new Object[] {item.getItemProperty("Name").getValue().toString(),
14                item.getItemProperty("Father").getValue().toString()},null);

The null in the end does that. From the javadocs for Table.addItem(Object cells, Object itemId):

so the table creates an id that is int.
You code would work if you’d call something like prueba.setParent(4,2);

What you probably would like to do is use manual item id’s. Something like

Item pruebaItem = prueba.addItem(item.getItemProperty("Name").getValue());
pruebaItem.getItemProperty("Name").setValue(item.getItemProperty("Name").getValue());
pruebaItem.getItemProperty("Father").setValue(item.getItemProperty("Father").getValue());

Then you can use something like

prueba.setParent("Steve", "Bob");

or just use the item id’s that you get, like prueba.getItem(i);.

Your copying of items from one table to another looks like a weird thing to do. A little hard to say as I just see a fragment of the code. Also, it is a good practice to use only English in code (referring to prueba). It would be easier to help that way.

Making things more complicated than they should be is like a gift I have…

thank you very much for your help, it worked perfect!!!

regards,

Hugo