How can I place a button in the Columnheader of CheckboxTableviewer ? And when I click that button I want all rows to be selected

StackOverflow https://stackoverflow.com/questions/22376268

  •  14-06-2023
  •  | 
  •  

Question

How can I place a button in the Columnheader of CheckboxTableviewer ? And when I click that button I want all rows to be selected. My table has 10 columns,

  1. I want a button in the columnheader,
  2. when I click that button I want all the rows of the table to be selected.

This is my table

    final CheckboxTableViewer dataTable = CheckboxTableViewer.newCheckList(TableComposite2, SWT.MULTI | SWT.H_SCROLL   
                | SWT.V_SCROLL | SWT.BORDER |SWT.DM_FILL_BACKGROUND|SWT.FULL_SELECTION);
        dataTable .getTable().setHeaderVisible(true);
        dataTable .getTable().setLinesVisible(true);
        dataTable .setContentProvider(new ArrayContentProvider());


    //Action Check box
        TableColumn columnCHead=new TableColumn(dataTable .getTable(),SWT.NONE);
        columnCHead.setText("Delete");

        columnCHead.setWidth(50);
        // setting column input
        TableViewerColumn columnC=new TableViewerColumn(dataTable ,columnCHead);
        columnC.setLabelProvider(new ColumnLabelProvider()
        {
            public String getText(Object Element)
            {

                return null;
            }
        });

        TableColumn columnFS1Head=new TableColumn(dataTable .getTable(),SWT.NONE);
        columnFS1Head.setText("SOURCE DIRECTORY");
        columnFS1Head.setWidth(300);

        TableViewerColumn columnFS1=new TableViewerColumn(dataTable ,columnFS1Head);
        columnFS1.setLabelProvider(new ColumnLabelProvider()
        {
            public String getText(Object Element)
            {
                AgedFileMaster a=(AgedFileMaster)Element;
                return a.getDIRECTORY_PATH();
            }

In the first column, I want that button instead of text "delete". Anyone please help. I am beginner to SWT.

Était-ce utile?

La solution

TableColumn already behaves like a button, just use addSelectionListener to listen for the button being pressed. You can't easily add controls to the column header.

To select everything call

Object [] elements = get all the elements in your data model

dataTable.setSelecton(new StructuredSelection(elements));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top