Reputation: 21
I have a table with 3 columns say type,name and value.
For example my table has the following values:
Type Name Value +++++++++++++++++++++++ Int id 0 String name null
How to get these values from the table and set to a list.
TableItem[] items = voTable.getItems();
List<VogenBean> lstTableValue = new ArrayList<VogenBean>();
for (int i = 0; i < items.length; i++) {
System.out.println("Items length--" + items.length);
VogenBean bean = new VogenBean();
bean.setClassName(domainName);
bean.setAttrName(typeLabel.getText());
bean.setMethodName(nameLabel.getText());
bean.setAttrInit(valueLabel.getText());
/*
* tableValue = domainName + ":" + typeLabel.getText() + ":" +
* nameLabel.getText()+":"+valueLabel.getText();
* System.out.println("Value--"+tableValue);
*/
lstTableValue.add(bean);
}
for (Iterator iterator = lstTableValue.iterator(); iterator.hasNext();) {
VogenBean vo = (VogenBean) iterator.next();
System.out.println("Class Name--" + vo.getClassName());
System.out.println("Attr Name--" + vo.getAttrName());
System.out.println("Method Name--" + vo.getMethodName());
System.out.println("Attr Init--" + vo.getAttrInit());
}
return lstTableValue;
This is my code. I'm getting only last field in the table. Please help.
Upvotes: 0
Views: 2056
Reputation: 3241
If you want to get the value of a certain row in table based on selection, you can use Table#getSelection()
. In case you are using a TableViewer
, you have to do a TableViewer#getSelection()
.
But if you want to just iterate through a table and get all values, just use Table#getItems()
. Each item is a TableItem
and you can get values for each column by using TableItem#getText(int columnIndex)
.
Does that answer your question?
Upvotes: 1