07-12-2017 05:12 AM
Hello everyone,
I want to have a column in a tree that only has a checkbox on each line. I read that in order for the users to be able to interact with the checkbox, I have to set the tree's ATTR_TREE_EDITABLE_CELLS to TRUE. However, I do NOT want the tree to be editable (none of its cells). So, how could I do this?
07-12-2017 07:49 AM
Well, editable cells are independent to checkboxes. If the tree is in indicator mode you cannot toggle its checkboxes (and edit item labels as well, for that matters), but in any other mode you can always edit the tree item label (= cell in the first column) with F2. Editable cells attribute only affects cells in columns from the second on.
Given this, the only workaround you I can imagine to disable the ability to modify tree item values is to add this callback to the tree:
int CVICALLBACK TreeCallback (int panel, int control, int event, void *callbackData,
int eventData1, int eventData2) { if (event != EVENT_EDIT_MODE_STATE_CHANGE) return 0; SetCtrlAttribute (panel, control, ATTR_TREE_RUN_STATE, VAL_SELECT_STATE); return 0; }
This callback intercepts the change in run state from select to edit and restores the select mode. The callback overcomes tree "editable cells" attribute.
07-12-2017 08:46 AM - edited 07-12-2017 08:47 AM
Thank you very much. Sadly, it seemed to also break the checkboxes (I could see them being checked/unchecked, but what should have happend on selecting them didn't seem to occur anymore). Still, inspired from your idea, this actually seems to work:
int CVICALLBACK TreeCallback (int panel, int control, int event, void *callbackData,
int eventData1, int eventData2) {
int line, col;
GetActiveTreeCell(panel, control, &line, &col);
if(col != CHECKBOX_COL)
SetCtrlAttribute(panel, control, ATTR_TREE_RUN_STATE, VAL_SELECT_STATE);
return 0;
}
07-12-2017 08:49 AM
Ok I understand, I didn't focused on the possibility to have checkboxes also in columns 2+.
I'm glad I helped you to find a feasible solution.
07-12-2017 09:28 AM
Oh, I see :). The item checkboxes (those in column 1, associated with the items) were working indeed with the code you provided.
07-14-2017 05:05 PM
Your solution can flicker a little bit, since it is going into edit mode and then exiting out of edit mode in the callback.
A better solution is to swallow the EVENT_BEGIN_EDIT_TREE_CELL event if the cell that is going into edit mode doesn't have a checkbox in it.
int CVICALLBACK TreeCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int swallow = 0; switch (event) { case EVENT_BEGIN_EDIT_TREE_CELL: int checkBoxColumn = 1; // or whichever column your checkboxes are in int col = eventData2; if (col != checkBoxColumn) swallow = 1; break; } return swallow; }
This way, the cell is never put into edit mode, and there is no flicker.
07-15-2017 04:57 PM
Thanks Jared, that is what I was looking for: a change event to swallow. I wasn't able to find it so I ended up playing with the run state.
Your solution is surely better since it operates before the user interface is updated to the new state.