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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With