2

我希望我的 ComboBoxCellEditor 能够有 3 个选择。现在它只有 Yes 或 No。我希望它有 Yes、No、Both。

此外,除非单击单元格,否则组合框选择值不会显示在表格中。除非他们单击空单元格,否则很难判断表格单元格是否可以选择。我希望它至少显示向下箭头。
我已经阅读了一些内容,您可以解决此问题的唯一方法是设置默认值。

  1. 我不确定如何添加第三个值。我将添加我的代码尝试添加第三个值

  2. 如何在不先单击单元格的情况下将组合框显示在表格中?

.

public class OptionEditingSupport extends EditingSupport {

    private ComboBoxCellEditor cellEditor;

    public OptionEditingSupport(ColumnViewer viewer) {
        super(viewer);
        cellEditor = new ComboBoxCellEditor(((TableViewer)viewer).getTable(), new String[]{"Yes", "No", "Both"}, SWT.READ_ONLY);

    }

    protected CellEditor getCellEditor(Object element) {
        return cellEditor;
    }

    protected boolean canEdit(Object element) {
        return true;
    }

    protected Object getValue(Object element) {
        return 0;
    }

    protected void setValue(Object element, Object value) 
    {
        if((element instanceof AplotDatasetData) && (value instanceof Integer)) {
            Integer choice = (Integer)value;
            String option = (choice == 0? "Yes":"No":"Both"); **<- Error Here
            ((AplotDatasetData)element).setMarkupValue(option);
            getViewer().update(element, null);
        }
    }
}
4

2 回答 2

1

条件运算符

x ? y : z

是一个三元运算符,它在内部执行:

if(x)
    y;
else
    z;

因此,您只能将其与三个组件一起使用。改为使用if else if else

Integer choice = (Integer)value;
String option = "";

if(choice == 0)
    option = "Yes";
else if(choice == 1)
    option = "No";
else
    option = "Both";
于 2012-09-10T17:56:05.293 回答
0

TableEditor可用于在表格单元格顶部显示任何小部件。它应该通过显示 Combobox 来解决您的问题,让用户知道该行和列可以选择。

我不确定我是否理解您关于 3 个选项的问题。

于 2012-09-11T01:41:51.790 回答