|
Re: How select an item in a Table ? [message #461733 is a reply to message #461731] |
Wed, 28 September 2005 21:07 |
Eclipse User |
|
|
|
Originally posted by: sunil_kamath.nohotspammail.com
"Nicolas Silb" <NiSJunk@DigitalAirways.com> wrote in message
news:dhetcc$8b0$1@news.eclipse.org...
>I want the first element to be selected in a viewer.
>
> I tried:
>
> public void createPartControl(Composite parent) {
>
> fViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL |
> SWT.V_SCROLL);
>
> ...
>
> final Table table = fViewer.getTable();
>
> int selectionCount = table.getSelectionCount();
>
> if(selectionCount==0) {
>
> table.setSelection(0);
>
> }
>
>
fViewer.setSelection(new StructuredSelection(obj));
where obj is the first element in your viewer input.
---
Sunil
|
|
|
|
Re: How select an item in a Table ? [message #461737 is a reply to message #461735] |
Thu, 29 September 2005 04:19 |
Eclipse User |
|
|
|
Originally posted by: sunil_kamath.nohotspammail.com
"Nicolas Silb" <NiSJunk@DigitalAirways.com> wrote in message
news:dhf4k8$ho5$1@news.eclipse.org...
> Where should i put this? if i put it after creating the viewer, there are
> no content yet and it fails;
>
Obviously. If there is no content, there is no way to select an item.
> I tried:
>
> public void createPartControl(Composite parent) {
>
> fViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL |
> SWT.V_SCROLL);
>
> fViewer.setContentProvider(new ViewContentProvider());
>
> fViewer.setLabelProvider(new ViewLabelProvider());
>
> fViewer.setSorter(new ViewerSorter());
>
>
> addSelectionChangedListener(Repository.getInstance());
>
At which point are you calling fViewer.setInput()?
>
> ISelection selection = new
> StructuredSelection(fViewer.getTable().getItem(0));
>
> fViewer.setSelection(selection, true);
>
This won't work. It expects the contents of the StructuredSelection to be an
element from your model- not the table item itself.
What is the input for your TableViewer?
---
Sunil
|
|
|
|
Powered by
FUDForum. Page generated in 0.03585 seconds