0

我目前正在使用 Nebula GridTable 并希望为表的行和列实现复制和粘贴功能。行的选择是开箱即用的,但是如果我按下标题单元格,我希望选择一列。GridTableViewer 创建如下

new GridTableViewer(parent, SWT.FULL_SELECTION | SWT.V_SCROLL | 
SWT.H_SCROLL | SWT.MULTI |SWT.WRAP | SWT.VIRTUAL)

为此,我为网格实现了一个 SelectionListener,如下所示:

v.getGrid().addSelectionListener(new SelectionListener(){

        @Override
        public void widgetSelected(SelectionEvent e) 
        {
            v.getGrid().selectColumn(e.y);
            v.getGrid().update();

        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // TODO Auto-generated method stub

        }

      });

调试器让我建议选择该列,但它没有在 UI 中突出显示。我该怎么做才能使多列选择和突出显示工作?

最好的问候,克里斯托夫

4

1 回答 1

1

我自己发现了,我很难解决。GridViewer 的配置是正确的,但它对网格上的单元格选择标志很重要。所以我添加了以下行以启用单元格选择

tableViewer.getGrid().setCellSelectionEnabled(true);

通过点击表头来选择一列可以实现如下。

column.addSelectionListener(new SelectionListener(){

        @Override
        public void widgetSelected(SelectionEvent e) 
        {
            int column = ((GridColumn) e.item).getCellRenderer().getColumn();
            tableViewer.getGrid().selectColumn(column);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) { }

    });
于 2017-01-05T18:30:02.743 回答