Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set desired selection in comboviewer programatically

I want to set a value to the ComboViewer programatically. I'm trying to get the value from an object and set it by using setSelection(Iselection) in this way viewer.setSelection(new StructuredSelection(Object) , but the value is not updated on the ComboViewer Selection. Could any one help me on how to set the selection of ComboViewer programatically?

like image 900
Juseeth Avatar asked Oct 18 '25 13:10

Juseeth


1 Answers

I did that recently. You need to focus on if the values that are being set in the combo and the value you are setting match. Try printing them or stepping through.

This is what needs to be done -

// set up comboViewer
comboViewer = new ComboViewer(leftSectionComposite, SWT.READ_ONLY);
comboViewer.setContentProvider(new ArrayContentProvider());
comboViewer.setLabelProvider(new LabelProvider()); // Use your label provider if possible.
comboViewer.setInput(YOURVALUES);

// set value

final ISelection selection = new StructuredSelection(valueFromComboThatYouWantToSet);
comboViewer.setSelection(selection);
like image 73
ND27 Avatar answered Oct 21 '25 02:10

ND27



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!