PDA

View Full Version : How can i EditorGrid row Validation



TrojanMyth
10 Oct 2011, 7:34 AM
Dear all;

I must row value validation in editor grid.

Sample

I have 3 columns (text1,text2,combo1).
I want to set text1 cols text editor allow blank is false.

How can i validate this action?

catalin.ciobanu
10 Oct 2011, 11:58 PM
you should set the validation to the editor .. not to the grid cell

you know .. column.setEditor (my textfield with wanted validation)

TrojanMyth
11 Oct 2011, 12:26 AM
Yes. I know but
Record's setValid method documents says :
Sets whether the record is valid (defaults to true). The valid state of a
record is not modified or changed by the record itself. Both EditorGrid and
FieldBinding will set the valid state of the record to match the field's
valid state after an edit completes.

I wrote fallowing code into my extended EditorGrid class.
this code solved my problem.

Have a more professional solution, I wonder if it



public boolean isValid(int rowIndex, int colIndex) { if (!getColumnModel().isCellEditable(colIndex)) { return true; } Editor ed = getColumnModel().getEditor(colIndex); if (ed == null) { return true; } if (getDataSet().getAt(rowIndex) == null) { return false; } if (getDataSet().getRecord(getDataSet().getAt(rowIndex)) == null) { return true; } String field = getColumnModel().getDataIndex(colIndex); if (ed instanceof ComboBoxCellEditor) { ModelData m = (ModelData) ed.preProcessValue(getDataSet().getRecord(getDataSet().getAt(rowIndex)).get(field)); ed.getField().setValue(m); } else { ed.getField().setValue(getDataSet().getRecord(getDataSet().getAt(rowIndex)).get(field)); } return ed.getField().isValid(true); }