Reputation: 491
I am implementing SWT CheckBoxTableViewer in my Project. Can somebody please tell me how to get the row index of the selected checked item ?
Upvotes: 3
Views: 2942
Reputation: 572
Getting Row index of Checked Item in CheckBoxTableViewer In SWT
public void mouseDown(MouseEvent event) {
Point point = new Point(event.x, event.y);
TableItem item = table.getItem(point);
if (item != null) {
TableItem items[]=table.getItems();
for(int i=0;i<table.getItemCount();i++){
if(items[i].getChecked())
{
System.out.println("Row index: "+(i+1));
}
}
}
Upvotes: 0
Reputation: 111142
Something like this:
final TableItem [] items = tableViewer.getTable().getItems();
for (int i = 0; i < items.length; ++i) {
if (items[i].getChecked())
... handle checked
}
You can use CheckBoxTableViewer.getCheckedElements()
if you just want the checked objects (which uses a loop similar to the above).
Upvotes: 3
Reputation: 36894
How about:
for (int i = 0; i < viewer.getTable().getItemCount(); i++)
{
if (viewer.getChecked(viewer.getElementAt(i)))
System.out.println(i);
}
Upvotes: 1