LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Checkboxes in a non-editable tree

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?

0 Kudos
Message 1 of 7
(2,866 Views)

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.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 7
(2,839 Views)

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;
}

 

0 Kudos
Message 3 of 7
(2,829 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 7
(2,824 Views)

Oh, I see :). The item checkboxes (those in column 1, associated with the items) were working indeed with the code you provided.

0 Kudos
Message 5 of 7
(2,819 Views)

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.

0 Kudos
Message 6 of 7
(2,788 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 7
(2,779 Views)