Reputation: 29550
It is quiet easy to create a Table
with a checkbox column, e.g., using the SWT.CHECK
flag. But how to make checkboxes in certain table rows not editable while those in other rows remain editable?
Upvotes: 3
Views: 6054
Reputation: 1159
I had faced a similar problem and i was able to solve it in the table using SWT.check. In the widgetSelected Event of the table you can try the following code:
TableItem[] item = table.getItems();
for(int j=0; j<item.length;j++)
{
TableItem tblItem = item[j];
if (tblItem.getChecked())
{
table.setSelection(j);
if(codition for the checkbox to be non-Editable written here)
{
item[table.getSelectionIndex()].setChecked(false);
}
}
}
In the above code after the table has been filled and when the user tries to check any item in the table the above code should be called. When the checkbox is clicked if the condition meets for the checkBox to be non-editable the checkbox is not selected otherwise it is selected.In this way in a table certain rows can be editable while others will be non-editable according to the required conditon.
Upvotes: 2
Reputation: 6406
I don't know a simple way of doing that.
But I see two possible solutions: There is a JFace Snippet doing a rather extreme hack to emulate natively looking checkboxes in tables with images here.
And then you could put own checkboxes into a plain Table, like this. That way you can control the state of every checkbox on your own.
I'd go with the 2nd solution.
Upvotes: 3
Reputation: 2489
try this:
table.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if( event.detail == SWT.CHECK ) {
event.detail = SWT.NONE;
event.type = SWT.None;
event.doIt = false;
((TableItem)event.item).setChecked(false);
}
}
});
Upvotes: 2