[英]how to select entire tableviewer row when checkbox clicked (first column of the table has checkboxes in each row)
am beginner to SWT, anyone please help, my problem is: i have a table, which has 10 Columns, the first column has Check box and the rest of the column are filled from Database, when i check the checkbox i want that perticular row to be selected, 我是SWT的初学者,请提供帮助,我的问题是:我有一个表,其中有10列,第一列有Check框,其余的列是从Database填充的,当我选中复选框时,我想要该垂直行被选中
i am pasting my table code below, 我在下面粘贴表格代码,
public static void main(String arg[])
{
// shell and display declared here
mainTable = new TableViewer(content, SWT.H_SCROLL| SWT.V_SCROLL | SWT.BORDER |SWT.DM_FILL_BACKGROUND|SWT.FULL_SELECTION);
mainTable .getTable().setHeaderVisible(true);
mainTable .getTable().setLinesVisible(true);
mainTable .setContentProvider(new ArrayContentProvider());
// COLUM FOR PLACING THE CHECK BOXES
TableColumn columncOL=new TableColumn(mainTable .getTable(),SWT.NONE);
columncOL.setText("");
columncOL.setWidth(40);
TableViewerColumn columnaC=new TableViewerColumn(mainTable ,columncOL);
columnaC.setLabelProvider(new ColumnLabelProvider(){
Map<Object, Button> buttons = new HashMap<Object, Button>();
@Override
public void update(ViewerCell cell) {
TableItem item = (TableItem) cell.getItem();
Button button;
if(buttons.containsKey(cell.getElement()))
{
button = buttons.get(cell.getElement());
}
else
{
button = new Button((Composite) cell.getViewerRow().getControl(),SWT.CHECK);
String s = "Item 1";
button.setData(s, "Some other info or object here");
s = "Item 2";
button.setData(s, "This is item two");
//buttons.put(cell.getElement(), button);
}
TableEditor editor = new TableEditor(item.getParent());
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.setEditor(button , item, cell.getColumnIndex());
editor.layout();
}
});
// CREATING 1st COLUMNS
TableColumn column1Head=new TableColumn(mainTable.getTable(),SWT.NONE);
column1Head.setText("col1");
column1Head.setWidth(200);
// setting column input
TableViewerColumn column1=new TableViewerColumn(mainTable,column1Head);
column1.setLabelProvider(new ColumnLabelProvider()
{
public String getText(Object Element)
{
Student ap=(Student )Element;
return ap.col1();
}
});
}
like this am creating remaing 8 columns i want to select the entire row when a perticluar check box checked . 像这样创建剩余的8列,我想在选中Perticluar复选框时选择整行。 any one pleeeease help me As early as possible....
谁能尽快帮助我...
Use CheckboxTableViewer
to show a table with check boxes: 使用
CheckboxTableViewer
显示带有复选框的表:
mainTable = CheckboxTableViewer.newCheckList(content, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
To select the line when a check box is ticked you will need to use addCheckStateListener
to select the checked row, something like: 要在勾选复选框时选择该行,您将需要使用
addCheckStateListener
来选择选中的行,例如:
mainTable.addCheckStateListener(new ICheckStateListener()
{
@Override
public void checkStateChanged(CheckStateChangedEvent event)
{
if (event.getChecked())
mainTable.setSelection(new StructuredSelection(event.getObject()));
}
});
Easy way :first column of the table has checkboxes in each row can selected or not
简单方法:表格的第一列每行都有复选框,可以选择是否
CheckboxTableViewer tableViewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.FULL_SELECTION);
Table table = tableViewer.getTable();
table.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event e) {
Table table = (Table) e.widget;
TableItem item = table.getItem(table.getSelectionIndex());
for (int col = 0; col < table.getColumnCount(); col++)
{
//Table_Column Checked or Not
if(item.getChecked())
//return true
//all ready checked(true) to change unchecked(false)
item.setChecked(false);
else
//unchecked(false) to checked(true) each row
item.setChecked(true);
}
}
}
this is useful for you....thanks 这对您很有用....谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.