1

I have a tableviewer inside a plugin with a view. The tableviewer has 5 columns. I need the data in the rows when I select the row. For example: when I select the row 1, the listener should store in a variable the data for column 1 row 1.

I have used this to get the data in the selected row but it returns the data for the first column only:

table.addListener(SWT.DefaultSelection, new Listener() {       
    public void handleEvent(Event event) {
          TableItem[] selection = table.getSelection();
          for (int i = 0; i < selection.length; i++)
          {                 
          System.out.println(selection[i].getText());
          }                    
    }
  });

How to get the data in all the columns of the row?

flavio.donze
  • 7,432
  • 9
  • 58
  • 91
John Smith
  • 777
  • 2
  • 14
  • 37
  • You want to select single cells of your viewer? http://stackoverflow.com/questions/6503057/eclipse-rcp-how-to-select-a-single-cell-in-tableviewer –  Sep 08 '14 at 09:17

1 Answers1

1

Use TableViewer.addSelectionChangedListener

viewer.addSelectionChangedListener(new ISelectionChangedListener() {
  @Override
  public void selectionChanged(final SelectionChangedEvent event)
  {
    IStructuredSelection selection = (IStructuredSelection)event.getSelection();

    RowData rowData = (RowData)selection.getFirstElement();

    ....
  }
});

where RowData is your model object for the row

greg-449
  • 109,219
  • 232
  • 102
  • 145